From dc59332fdbe9b654a69a3410adc6904bdc9e6548 Mon Sep 17 00:00:00 2001 From: shivam-pareek Date: Mon, 21 Oct 2024 18:04:31 +0530 Subject: [PATCH 1/6] feat: logs-exports api integrated --- portkey_ai/__init__.py | 4 + portkey_ai/api_resources/__init__.py | 4 + portkey_ai/api_resources/apis/__init__.py | 4 +- portkey_ai/api_resources/apis/logs_export.py | 271 ++++++++++++++++++ portkey_ai/api_resources/client.py | 6 +- .../api_resources/types/logs_export_type.py | 144 ++++++++++ portkey_ai/api_resources/utils.py | 2 +- 7 files changed, 431 insertions(+), 4 deletions(-) create mode 100644 portkey_ai/api_resources/apis/logs_export.py create mode 100644 portkey_ai/api_resources/types/logs_export_type.py diff --git a/portkey_ai/__init__.py b/portkey_ai/__init__.py index 1cc2395..154f4e4 100644 --- a/portkey_ai/__init__.py +++ b/portkey_ai/__init__.py @@ -87,6 +87,8 @@ AsyncApiKeys, VirtualKeys, AsyncVirtualKeys, + LogsExport, + AsyncLogsExport, ) from portkey_ai.version import VERSION @@ -193,4 +195,6 @@ "AsyncApiKeys", "VirtualKeys", "AsyncVirtualKeys", + "LogsExport", + "AsyncLogsExport" ] diff --git a/portkey_ai/api_resources/__init__.py b/portkey_ai/api_resources/__init__.py index cb1a40e..04e75ec 100644 --- a/portkey_ai/api_resources/__init__.py +++ b/portkey_ai/api_resources/__init__.py @@ -75,6 +75,8 @@ AsyncApiKeys, VirtualKeys, AsyncVirtualKeys, + LogsExport, + AsyncLogsExport, ) from .utils import ( Modes, @@ -185,4 +187,6 @@ "AsyncApiKeys", "VirtualKeys", "AsyncVirtualKeys", + "LogsExport", + "AsyncLogsExport" ] diff --git a/portkey_ai/api_resources/apis/__init__.py b/portkey_ai/api_resources/apis/__init__.py index 7d12340..20250c7 100644 --- a/portkey_ai/api_resources/apis/__init__.py +++ b/portkey_ai/api_resources/apis/__init__.py @@ -78,7 +78,7 @@ from .api_keys import ApiKeys, AsyncApiKeys from .virtual_keys import VirtualKeys, AsyncVirtualKeys - +from .logs_export import LogsExport, AsyncLogsExport __all__ = [ "Completion", "AsyncCompletion", @@ -159,4 +159,6 @@ "AsyncApiKeys", "VirtualKeys", "AsyncVirtualKeys", + "LogsExport", + "AsyncLogsExport" ] diff --git a/portkey_ai/api_resources/apis/logs_export.py b/portkey_ai/api_resources/apis/logs_export.py new file mode 100644 index 0000000..267fb7d --- /dev/null +++ b/portkey_ai/api_resources/apis/logs_export.py @@ -0,0 +1,271 @@ +from typing import Any, Dict, List, Optional +from portkey_ai.api_resources.base_client import APIClient, AsyncAPIClient +from urllib.parse import urlencode +from portkey_ai.api_resources.apis.api_resource import APIResource, AsyncAPIResource +from portkey_ai.api_resources.types.logs_export_type import ( + LogsExportCreateResponse, + LogsExportListResponse, + LogsExportUpdateResponse, + LogsExportCancelResponse, + LogsExportRetrieveResponse, + LogsExportStartResponse, + LogsExportDownloadResponse, +) +from portkey_ai.api_resources.utils import GenericResponse +from portkey_ai.api_resources.utils import PortkeyApiPaths + + +class LogsExport(APIResource): + def __init__(self, client: APIClient) -> None: + super().__init__(client) + + def create( + self, + *, + filters: Optional[Dict[str, Any]] = None, + workspace_id: Optional[str] = None, + description: Optional[str] = None, + requested_data: Optional[List[str]] = None, + ) -> LogsExportCreateResponse: + body = { + "filters": filters, + "workspace_id": workspace_id, + "description": description, + "requested_data": requested_data, + } + return self._post( + f"{PortkeyApiPaths.LOGS_EXPORT_API}", + body=body, + params=None, + cast_to=LogsExportCreateResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + def retrieve(self, *, exportId: str) -> LogsExportRetrieveResponse: + return self._get( + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}", + params=None, + body=None, + cast_to=LogsExportRetrieveResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + def list( + self, + *, + workspace_id: Optional[str] = None, + ) -> LogsExportListResponse: + query = { + "workspace_id": workspace_id, + } + filtered_query = {k: v for k, v in query.items() if v is not None} + query_string = urlencode(filtered_query) + return self._get( + f"{PortkeyApiPaths.LOGS_EXPORT_API}?{query_string}", + params=None, + body=None, + cast_to=LogsExportListResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + def update( + self, + *, + exportId: Optional[str] = None, + workspace_id: Optional[str] = None, + filters: Optional[Dict[str, Any]] = None, + requested_data: Optional[List[str]] = None, + ) -> LogsExportUpdateResponse: + body = { + "workspace_id": workspace_id, + "filters": filters, + "requested_data": requested_data, + } + return self._put( + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}", + body=body, + params=None, + cast_to=LogsExportUpdateResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + def start( + self, + *, + exportId: Optional[str], + ) -> LogsExportStartResponse: + return self._post( + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}/start", + body=None, + params=None, + cast_to=LogsExportStartResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + def cancel( + self, + *, + exportId: Optional[str], + ) -> LogsExportCancelResponse: + return self._post( + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}/cancel", + body=None, + params=None, + cast_to=LogsExportCancelResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + def download( + self, + *, + exportId: Optional[str], + ) -> LogsExportDownloadResponse: + return self._get( + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}/download", + params=None, + body=None, + cast_to=LogsExportDownloadResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + +class AsyncLogsExport(AsyncAPIResource): + def __init__(self, client: AsyncAPIClient) -> None: + super().__init__(client) + + async def create( + self, + *, + filters: Optional[Dict[str, Any]] = None, + workspace_id: Optional[str] = None, + description: Optional[str] = None, + requested_data: Optional[List[str]] = None, + ) -> LogsExportCreateResponse: + body = { + "filters": filters, + "workspace_id": workspace_id, + "description": description, + "requested_data": requested_data, + } + return await self._post( + f"{PortkeyApiPaths.LOGS_EXPORT_API}", + body=body, + params=None, + cast_to=LogsExportCreateResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + async def retrieve(self, *, exportId: str) -> LogsExportRetrieveResponse: + return await self._get( + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}", + params=None, + body=None, + cast_to=LogsExportRetrieveResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + async def list( + self, + *, + workspace_id: Optional[str] = None, + ) -> LogsExportListResponse: + query = { + "workspace_id": workspace_id, + } + filtered_query = {k: v for k, v in query.items() if v is not None} + query_string = urlencode(filtered_query) + return await self._get( + f"{PortkeyApiPaths.LOGS_EXPORT_API}?{query_string}", + params=None, + body=None, + cast_to=LogsExportListResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + async def update( + self, + *, + exportId: Optional[str] = None, + workspace_id: Optional[str] = None, + filters: Optional[Dict[str, Any]] = None, + requested_data: Optional[List[str]] = None, + ) -> LogsExportUpdateResponse: + body = { + "workspace_id": workspace_id, + "filters": filters, + "requested_data": requested_data, + } + return await self._put( + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}", + body=body, + params=None, + cast_to=LogsExportUpdateResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + async def start( + self, + *, + exportId: Optional[str], + ) -> LogsExportStartResponse: + return await self._post( + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}/start", + body=None, + params=None, + cast_to=LogsExportStartResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + async def cancel( + self, + *, + exportId: Optional[str], + ) -> LogsExportCancelResponse: + return await self._post( + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}/cancel", + body=None, + params=None, + cast_to=LogsExportCancelResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + async def download( + self, + *, + exportId: Optional[str], + ) -> LogsExportDownloadResponse: + return await self._get( + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}/download", + params=None, + body=None, + cast_to=LogsExportDownloadResponse, + stream=False, + stream_cls=None, + headers={}, + ) \ No newline at end of file diff --git a/portkey_ai/api_resources/client.py b/portkey_ai/api_resources/client.py index 9f641fe..54c2683 100644 --- a/portkey_ai/api_resources/client.py +++ b/portkey_ai/api_resources/client.py @@ -31,7 +31,7 @@ class Portkey(APIClient): configs: apis.Configs api_keys: apis.ApiKeys virtual_keys: apis.VirtualKeys - + logs_export: apis.LogsExport class beta: assistants: apis.Assistants threads: apis.Threads @@ -143,6 +143,7 @@ def __init__( self.configs = apis.Configs(self) self.api_keys = apis.ApiKeys(self) self.virtual_keys = apis.VirtualKeys(self) + self.logs_export= apis.LogsExport(self) self.beta = self.beta(self) # type: ignore def copy( @@ -246,7 +247,7 @@ class AsyncPortkey(AsyncAPIClient): configs: apis.AsyncConfigs api_keys: apis.AsyncApiKeys virtual_keys: apis.AsyncVirtualKeys - + logs_export: apis.AsyncLogsExport class beta: assistants: apis.AsyncAssistants threads: apis.AsyncThreads @@ -358,6 +359,7 @@ def __init__( self.configs = apis.AsyncConfigs(self) self.api_keys = apis.AsyncApiKeys(self) self.virtual_keys = apis.AsyncVirtualKeys(self) + self.logs_export=apis.AsyncLogsExport(self) self.beta = self.beta(self) # type: ignore def copy( diff --git a/portkey_ai/api_resources/types/logs_export_type.py b/portkey_ai/api_resources/types/logs_export_type.py new file mode 100644 index 0000000..83f5713 --- /dev/null +++ b/portkey_ai/api_resources/types/logs_export_type.py @@ -0,0 +1,144 @@ +import json +from typing import Any, Dict, List, Optional +from datetime import datetime +import httpx +from pydantic import BaseModel, PrivateAttr +from portkey_ai.api_resources.types.utils import parse_headers + + +class LogsExportCreateResponse(BaseModel): + id: Optional[str] + total: Optional[int] + object: Optional[str] + _headers: Optional[httpx.Headers] = PrivateAttr() + + def get_headers(self) -> Optional[Dict[str, str]]: + return parse_headers(self._headers) + + def __str__(self): + return json.dumps(self.dict(), indent=4) + + def __getitem__(self, key): + return getattr(self, key, None) + + def get(self, key: str, default: Optional[Any] = None): + return getattr(self, key, None) or default + + +class LogsExportListResponse(BaseModel): + object: Optional[str] + total: Optional[int] + data: Optional[List[Dict[str, Any]]] + _headers: Optional[httpx.Headers] = PrivateAttr() + + def get_headers(self) -> Optional[Dict[str, str]]: + return parse_headers(self._headers) + + def __str__(self): + return json.dumps(self.dict(), indent=4) + + def __getitem__(self, key): + return getattr(self, key, None) + + def get(self, key: str, default: Optional[Any] = None): + return getattr(self, key, None) or default + + +class LogsExportUpdateResponse(BaseModel): + id: Optional[str] + total: Optional[int] + object: Optional[str] + _headers: Optional[httpx.Headers] = PrivateAttr() + + def get_headers(self) -> Optional[Dict[str, str]]: + return parse_headers(self._headers) + + def __str__(self): + return json.dumps(self.dict(), indent=4) + + def __getitem__(self, key): + return getattr(self, key, None) + + def get(self, key: str, default: Optional[Any] = None): + return getattr(self, key, None) or default + + +class LogsExportCancelResponse(BaseModel): + message: Optional[str] + object: Optional[str] + _headers: Optional[httpx.Headers] = PrivateAttr() + + def get_headers(self) -> Optional[Dict[str, str]]: + return parse_headers(self._headers) + + def __str__(self): + return json.dumps(self.dict(), indent=4) + + def __getitem__(self, key): + return getattr(self, key, None) + + def get(self, key: str, default: Optional[Any] = None): + return getattr(self, key, None) or default + + +class LogsExportRetrieveResponse(BaseModel): + id: Optional[str] + organisation_id: Optional[str] + filters: Optional[Dict[str, Any]] + requested_data: Optional[List[str]] + status: Optional[str] + description: Optional[str] + created_at: Optional[datetime] + last_updated_at: Optional[datetime] + created_by: Optional[str] + workspace_id: Optional[str] + total_records: Optional[int] + object: Optional[str] + _headers: Optional[httpx.Headers] = PrivateAttr() + + def get_headers(self) -> Optional[Dict[str, str]]: + return parse_headers(self._headers) + + def __str__(self): + return json.dumps(self.dict(), indent=4) + + def __getitem__(self, key): + return getattr(self, key, None) + + def get(self, key: str, default: Optional[Any] = None): + return getattr(self, key, None) or default + + +class LogsExportStartResponse(BaseModel): + message: Optional[str] + object: Optional[str] + _headers: Optional[httpx.Headers] = PrivateAttr() + + def get_headers(self) -> Optional[Dict[str, str]]: + return parse_headers(self._headers) + + def __str__(self): + return json.dumps(self.dict(), indent=4) + + def __getitem__(self, key): + return getattr(self, key, None) + + def get(self, key: str, default: Optional[Any] = None): + return getattr(self, key, None) or default + + +class LogsExportDownloadResponse(BaseModel): + signed_url: Optional[str] + _headers: Optional[httpx.Headers] = PrivateAttr() + + def get_headers(self) -> Optional[Dict[str, str]]: + return parse_headers(self._headers) + + def __str__(self): + return json.dumps(self.dict(), indent=4) + + def __getitem__(self, key): + return getattr(self, key, None) + + def get(self, key: str, default: Optional[Any] = None): + return getattr(self, key, None) or default \ No newline at end of file diff --git a/portkey_ai/api_resources/utils.py b/portkey_ai/api_resources/utils.py index c11f677..10f2c3d 100644 --- a/portkey_ai/api_resources/utils.py +++ b/portkey_ai/api_resources/utils.py @@ -122,7 +122,7 @@ class PortkeyApiPaths(str, Enum, metaclass=MetaEnum): CONFIG_API = "/configs" API_KEYS_API = "/api-keys" VIRTUAL_KEYS_API = "/virtual-keys" - + LOGS_EXPORT_API = "/logs-export" class Options(BaseModel): method: str From 103cfb172148d647c058cfe539f1c80f13be1581 Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Fri, 1 Nov 2024 15:42:41 +0530 Subject: [PATCH 2/6] fix: linting --- portkey_ai/__init__.py | 2 +- portkey_ai/api_resources/__init__.py | 2 +- portkey_ai/api_resources/apis/__init__.py | 3 ++- portkey_ai/api_resources/apis/logs_export.py | 3 +-- portkey_ai/api_resources/client.py | 6 ++++-- portkey_ai/api_resources/types/logs_export_type.py | 2 +- portkey_ai/api_resources/utils.py | 3 ++- 7 files changed, 12 insertions(+), 9 deletions(-) diff --git a/portkey_ai/__init__.py b/portkey_ai/__init__.py index 154f4e4..423552a 100644 --- a/portkey_ai/__init__.py +++ b/portkey_ai/__init__.py @@ -196,5 +196,5 @@ "VirtualKeys", "AsyncVirtualKeys", "LogsExport", - "AsyncLogsExport" + "AsyncLogsExport", ] diff --git a/portkey_ai/api_resources/__init__.py b/portkey_ai/api_resources/__init__.py index 04e75ec..e5bd0b8 100644 --- a/portkey_ai/api_resources/__init__.py +++ b/portkey_ai/api_resources/__init__.py @@ -188,5 +188,5 @@ "VirtualKeys", "AsyncVirtualKeys", "LogsExport", - "AsyncLogsExport" + "AsyncLogsExport", ] diff --git a/portkey_ai/api_resources/apis/__init__.py b/portkey_ai/api_resources/apis/__init__.py index 20250c7..1f7e2c7 100644 --- a/portkey_ai/api_resources/apis/__init__.py +++ b/portkey_ai/api_resources/apis/__init__.py @@ -79,6 +79,7 @@ from .api_keys import ApiKeys, AsyncApiKeys from .virtual_keys import VirtualKeys, AsyncVirtualKeys from .logs_export import LogsExport, AsyncLogsExport + __all__ = [ "Completion", "AsyncCompletion", @@ -160,5 +161,5 @@ "VirtualKeys", "AsyncVirtualKeys", "LogsExport", - "AsyncLogsExport" + "AsyncLogsExport", ] diff --git a/portkey_ai/api_resources/apis/logs_export.py b/portkey_ai/api_resources/apis/logs_export.py index 267fb7d..4b51b9f 100644 --- a/portkey_ai/api_resources/apis/logs_export.py +++ b/portkey_ai/api_resources/apis/logs_export.py @@ -11,7 +11,6 @@ LogsExportStartResponse, LogsExportDownloadResponse, ) -from portkey_ai.api_resources.utils import GenericResponse from portkey_ai.api_resources.utils import PortkeyApiPaths @@ -268,4 +267,4 @@ async def download( stream=False, stream_cls=None, headers={}, - ) \ No newline at end of file + ) diff --git a/portkey_ai/api_resources/client.py b/portkey_ai/api_resources/client.py index 54c2683..0281ca7 100644 --- a/portkey_ai/api_resources/client.py +++ b/portkey_ai/api_resources/client.py @@ -32,6 +32,7 @@ class Portkey(APIClient): api_keys: apis.ApiKeys virtual_keys: apis.VirtualKeys logs_export: apis.LogsExport + class beta: assistants: apis.Assistants threads: apis.Threads @@ -143,7 +144,7 @@ def __init__( self.configs = apis.Configs(self) self.api_keys = apis.ApiKeys(self) self.virtual_keys = apis.VirtualKeys(self) - self.logs_export= apis.LogsExport(self) + self.logs_export = apis.LogsExport(self) self.beta = self.beta(self) # type: ignore def copy( @@ -248,6 +249,7 @@ class AsyncPortkey(AsyncAPIClient): api_keys: apis.AsyncApiKeys virtual_keys: apis.AsyncVirtualKeys logs_export: apis.AsyncLogsExport + class beta: assistants: apis.AsyncAssistants threads: apis.AsyncThreads @@ -359,7 +361,7 @@ def __init__( self.configs = apis.AsyncConfigs(self) self.api_keys = apis.AsyncApiKeys(self) self.virtual_keys = apis.AsyncVirtualKeys(self) - self.logs_export=apis.AsyncLogsExport(self) + self.logs_export = apis.AsyncLogsExport(self) self.beta = self.beta(self) # type: ignore def copy( diff --git a/portkey_ai/api_resources/types/logs_export_type.py b/portkey_ai/api_resources/types/logs_export_type.py index 83f5713..0b9f9f4 100644 --- a/portkey_ai/api_resources/types/logs_export_type.py +++ b/portkey_ai/api_resources/types/logs_export_type.py @@ -141,4 +141,4 @@ def __getitem__(self, key): return getattr(self, key, None) def get(self, key: str, default: Optional[Any] = None): - return getattr(self, key, None) or default \ No newline at end of file + return getattr(self, key, None) or default diff --git a/portkey_ai/api_resources/utils.py b/portkey_ai/api_resources/utils.py index 10f2c3d..14a139c 100644 --- a/portkey_ai/api_resources/utils.py +++ b/portkey_ai/api_resources/utils.py @@ -122,7 +122,8 @@ class PortkeyApiPaths(str, Enum, metaclass=MetaEnum): CONFIG_API = "/configs" API_KEYS_API = "/api-keys" VIRTUAL_KEYS_API = "/virtual-keys" - LOGS_EXPORT_API = "/logs-export" + LOGS_EXPORT_API = "/logs-export" + class Options(BaseModel): method: str From 80ab7256bf2586cf2cb28f7b5875e2fb6014d708 Mon Sep 17 00:00:00 2001 From: shivam-pareek Date: Mon, 4 Nov 2024 16:52:57 +0530 Subject: [PATCH 3/6] fix: snake_casing, api_paths, and types --- portkey_ai/__init__.py | 8 +-- portkey_ai/api_resources/__init__.py | 8 +-- portkey_ai/api_resources/apis/__init__.py | 6 +- .../apis/{logs_export.py => logs.py} | 56 +++++++++++-------- portkey_ai/api_resources/client.py | 2 +- .../{logs_export_type.py => logs_type.py} | 0 portkey_ai/api_resources/utils.py | 2 +- 7 files changed, 46 insertions(+), 36 deletions(-) rename portkey_ai/api_resources/apis/{logs_export.py => logs.py} (81%) rename portkey_ai/api_resources/types/{logs_export_type.py => logs_type.py} (100%) diff --git a/portkey_ai/__init__.py b/portkey_ai/__init__.py index 154f4e4..c79a919 100644 --- a/portkey_ai/__init__.py +++ b/portkey_ai/__init__.py @@ -87,8 +87,8 @@ AsyncApiKeys, VirtualKeys, AsyncVirtualKeys, - LogsExport, - AsyncLogsExport, + Logs, + AsyncLogs, ) from portkey_ai.version import VERSION @@ -195,6 +195,6 @@ "AsyncApiKeys", "VirtualKeys", "AsyncVirtualKeys", - "LogsExport", - "AsyncLogsExport" + "Logs", + "AsyncLogs" ] diff --git a/portkey_ai/api_resources/__init__.py b/portkey_ai/api_resources/__init__.py index 04e75ec..3a8fd3a 100644 --- a/portkey_ai/api_resources/__init__.py +++ b/portkey_ai/api_resources/__init__.py @@ -75,8 +75,8 @@ AsyncApiKeys, VirtualKeys, AsyncVirtualKeys, - LogsExport, - AsyncLogsExport, + Logs, + AsyncLogs, ) from .utils import ( Modes, @@ -187,6 +187,6 @@ "AsyncApiKeys", "VirtualKeys", "AsyncVirtualKeys", - "LogsExport", - "AsyncLogsExport" + "Logs", + "AsyncLogs" ] diff --git a/portkey_ai/api_resources/apis/__init__.py b/portkey_ai/api_resources/apis/__init__.py index 20250c7..4c92c9e 100644 --- a/portkey_ai/api_resources/apis/__init__.py +++ b/portkey_ai/api_resources/apis/__init__.py @@ -78,7 +78,7 @@ from .api_keys import ApiKeys, AsyncApiKeys from .virtual_keys import VirtualKeys, AsyncVirtualKeys -from .logs_export import LogsExport, AsyncLogsExport +from .logs import Logs, AsyncLogs __all__ = [ "Completion", "AsyncCompletion", @@ -159,6 +159,6 @@ "AsyncApiKeys", "VirtualKeys", "AsyncVirtualKeys", - "LogsExport", - "AsyncLogsExport" + "Logs", + "AsyncLogs" ] diff --git a/portkey_ai/api_resources/apis/logs_export.py b/portkey_ai/api_resources/apis/logs.py similarity index 81% rename from portkey_ai/api_resources/apis/logs_export.py rename to portkey_ai/api_resources/apis/logs.py index 267fb7d..f180236 100644 --- a/portkey_ai/api_resources/apis/logs_export.py +++ b/portkey_ai/api_resources/apis/logs.py @@ -2,7 +2,7 @@ from portkey_ai.api_resources.base_client import APIClient, AsyncAPIClient from urllib.parse import urlencode from portkey_ai.api_resources.apis.api_resource import APIResource, AsyncAPIResource -from portkey_ai.api_resources.types.logs_export_type import ( +from portkey_ai.api_resources.types.logs_type import ( LogsExportCreateResponse, LogsExportListResponse, LogsExportUpdateResponse, @@ -15,7 +15,12 @@ from portkey_ai.api_resources.utils import PortkeyApiPaths -class LogsExport(APIResource): +class Logs(APIResource): + def __init__(self, client: APIClient) -> None: + super().__init__(client) + self.exports=Exports(client) + +class Exports(APIResource): def __init__(self, client: APIClient) -> None: super().__init__(client) @@ -43,9 +48,9 @@ def create( headers={}, ) - def retrieve(self, *, exportId: str) -> LogsExportRetrieveResponse: + def retrieve(self, *, export_id: str) -> LogsExportRetrieveResponse: return self._get( - f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}", + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}", params=None, body=None, cast_to=LogsExportRetrieveResponse, @@ -77,7 +82,7 @@ def list( def update( self, *, - exportId: Optional[str] = None, + export_id: Optional[str] = None, workspace_id: Optional[str] = None, filters: Optional[Dict[str, Any]] = None, requested_data: Optional[List[str]] = None, @@ -88,7 +93,7 @@ def update( "requested_data": requested_data, } return self._put( - f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}", + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}", body=body, params=None, cast_to=LogsExportUpdateResponse, @@ -100,10 +105,10 @@ def update( def start( self, *, - exportId: Optional[str], + export_id: Optional[str], ) -> LogsExportStartResponse: return self._post( - f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}/start", + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}/start", body=None, params=None, cast_to=LogsExportStartResponse, @@ -115,10 +120,10 @@ def start( def cancel( self, *, - exportId: Optional[str], + export_id: Optional[str], ) -> LogsExportCancelResponse: return self._post( - f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}/cancel", + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}/cancel", body=None, params=None, cast_to=LogsExportCancelResponse, @@ -130,10 +135,10 @@ def cancel( def download( self, *, - exportId: Optional[str], + export_id: Optional[str], ) -> LogsExportDownloadResponse: return self._get( - f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}/download", + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}/download", params=None, body=None, cast_to=LogsExportDownloadResponse, @@ -143,7 +148,12 @@ def download( ) -class AsyncLogsExport(AsyncAPIResource): +class AsyncLogs(AsyncAPIResource): + def __init__(self, client: AsyncAPIClient) -> None: + super().__init__(client) + self.exports=AsyncExports(client) + +class AsyncExports(AsyncAPIResource): def __init__(self, client: AsyncAPIClient) -> None: super().__init__(client) @@ -171,9 +181,9 @@ async def create( headers={}, ) - async def retrieve(self, *, exportId: str) -> LogsExportRetrieveResponse: + async def retrieve(self, *, export_id: str) -> LogsExportRetrieveResponse: return await self._get( - f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}", + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}", params=None, body=None, cast_to=LogsExportRetrieveResponse, @@ -205,7 +215,7 @@ async def list( async def update( self, *, - exportId: Optional[str] = None, + export_id: Optional[str] = None, workspace_id: Optional[str] = None, filters: Optional[Dict[str, Any]] = None, requested_data: Optional[List[str]] = None, @@ -216,7 +226,7 @@ async def update( "requested_data": requested_data, } return await self._put( - f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}", + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}", body=body, params=None, cast_to=LogsExportUpdateResponse, @@ -228,10 +238,10 @@ async def update( async def start( self, *, - exportId: Optional[str], + export_id: Optional[str], ) -> LogsExportStartResponse: return await self._post( - f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}/start", + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}/start", body=None, params=None, cast_to=LogsExportStartResponse, @@ -243,10 +253,10 @@ async def start( async def cancel( self, *, - exportId: Optional[str], + export_id: Optional[str], ) -> LogsExportCancelResponse: return await self._post( - f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}/cancel", + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}/cancel", body=None, params=None, cast_to=LogsExportCancelResponse, @@ -258,10 +268,10 @@ async def cancel( async def download( self, *, - exportId: Optional[str], + export_id: Optional[str], ) -> LogsExportDownloadResponse: return await self._get( - f"{PortkeyApiPaths.LOGS_EXPORT_API}/{exportId}/download", + f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}/download", params=None, body=None, cast_to=LogsExportDownloadResponse, diff --git a/portkey_ai/api_resources/client.py b/portkey_ai/api_resources/client.py index 54c2683..ea58440 100644 --- a/portkey_ai/api_resources/client.py +++ b/portkey_ai/api_resources/client.py @@ -359,7 +359,7 @@ def __init__( self.configs = apis.AsyncConfigs(self) self.api_keys = apis.AsyncApiKeys(self) self.virtual_keys = apis.AsyncVirtualKeys(self) - self.logs_export=apis.AsyncLogsExport(self) + self.logs=apis.AsyncLogs(self) self.beta = self.beta(self) # type: ignore def copy( diff --git a/portkey_ai/api_resources/types/logs_export_type.py b/portkey_ai/api_resources/types/logs_type.py similarity index 100% rename from portkey_ai/api_resources/types/logs_export_type.py rename to portkey_ai/api_resources/types/logs_type.py diff --git a/portkey_ai/api_resources/utils.py b/portkey_ai/api_resources/utils.py index 10f2c3d..2ec77d0 100644 --- a/portkey_ai/api_resources/utils.py +++ b/portkey_ai/api_resources/utils.py @@ -122,7 +122,7 @@ class PortkeyApiPaths(str, Enum, metaclass=MetaEnum): CONFIG_API = "/configs" API_KEYS_API = "/api-keys" VIRTUAL_KEYS_API = "/virtual-keys" - LOGS_EXPORT_API = "/logs-export" + LOGS_EXPORT_API = "/logs/exports" class Options(BaseModel): method: str From f3894005ea4e1ca77356d37c968303facd18ba9f Mon Sep 17 00:00:00 2001 From: shivam-pareek Date: Tue, 5 Nov 2024 13:42:25 +0530 Subject: [PATCH 4/6] fix: logs export client --- portkey_ai/api_resources/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/portkey_ai/api_resources/client.py b/portkey_ai/api_resources/client.py index c7d40a4..fe2f0e1 100644 --- a/portkey_ai/api_resources/client.py +++ b/portkey_ai/api_resources/client.py @@ -31,7 +31,7 @@ class Portkey(APIClient): configs: apis.Configs api_keys: apis.ApiKeys virtual_keys: apis.VirtualKeys - logs_export: apis.LogsExport + logs: apis.Logs class beta: assistants: apis.Assistants @@ -144,7 +144,7 @@ def __init__( self.configs = apis.Configs(self) self.api_keys = apis.ApiKeys(self) self.virtual_keys = apis.VirtualKeys(self) - self.logs_export = apis.LogsExport(self) + self.logs = apis.Logs(self) self.beta = self.beta(self) # type: ignore def copy( @@ -248,7 +248,7 @@ class AsyncPortkey(AsyncAPIClient): configs: apis.AsyncConfigs api_keys: apis.AsyncApiKeys virtual_keys: apis.AsyncVirtualKeys - logs_export: apis.AsyncLogsExport + logs: apis.AsyncLogs class beta: assistants: apis.AsyncAssistants From 5309d0eaa5d49852a4e8bcd9314d425a33342cbd Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Tue, 5 Nov 2024 13:50:21 +0530 Subject: [PATCH 5/6] fix: linting --- portkey_ai/__init__.py | 2 +- portkey_ai/api_resources/__init__.py | 2 +- portkey_ai/api_resources/apis/__init__.py | 3 ++- portkey_ai/api_resources/apis/logs.py | 6 ++++-- portkey_ai/api_resources/client.py | 2 +- portkey_ai/api_resources/utils.py | 3 ++- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/portkey_ai/__init__.py b/portkey_ai/__init__.py index c79a919..e6ab0b3 100644 --- a/portkey_ai/__init__.py +++ b/portkey_ai/__init__.py @@ -196,5 +196,5 @@ "VirtualKeys", "AsyncVirtualKeys", "Logs", - "AsyncLogs" + "AsyncLogs", ] diff --git a/portkey_ai/api_resources/__init__.py b/portkey_ai/api_resources/__init__.py index 3a8fd3a..ebacc05 100644 --- a/portkey_ai/api_resources/__init__.py +++ b/portkey_ai/api_resources/__init__.py @@ -188,5 +188,5 @@ "VirtualKeys", "AsyncVirtualKeys", "Logs", - "AsyncLogs" + "AsyncLogs", ] diff --git a/portkey_ai/api_resources/apis/__init__.py b/portkey_ai/api_resources/apis/__init__.py index 4c92c9e..975b659 100644 --- a/portkey_ai/api_resources/apis/__init__.py +++ b/portkey_ai/api_resources/apis/__init__.py @@ -79,6 +79,7 @@ from .api_keys import ApiKeys, AsyncApiKeys from .virtual_keys import VirtualKeys, AsyncVirtualKeys from .logs import Logs, AsyncLogs + __all__ = [ "Completion", "AsyncCompletion", @@ -160,5 +161,5 @@ "VirtualKeys", "AsyncVirtualKeys", "Logs", - "AsyncLogs" + "AsyncLogs", ] diff --git a/portkey_ai/api_resources/apis/logs.py b/portkey_ai/api_resources/apis/logs.py index d4d5cb0..44092a7 100644 --- a/portkey_ai/api_resources/apis/logs.py +++ b/portkey_ai/api_resources/apis/logs.py @@ -17,7 +17,8 @@ class Logs(APIResource): def __init__(self, client: APIClient) -> None: super().__init__(client) - self.exports=Exports(client) + self.exports = Exports(client) + class Exports(APIResource): def __init__(self, client: APIClient) -> None: @@ -150,7 +151,8 @@ def download( class AsyncLogs(AsyncAPIResource): def __init__(self, client: AsyncAPIClient) -> None: super().__init__(client) - self.exports=AsyncExports(client) + self.exports = AsyncExports(client) + class AsyncExports(AsyncAPIResource): def __init__(self, client: AsyncAPIClient) -> None: diff --git a/portkey_ai/api_resources/client.py b/portkey_ai/api_resources/client.py index fe2f0e1..3fd5ddc 100644 --- a/portkey_ai/api_resources/client.py +++ b/portkey_ai/api_resources/client.py @@ -361,7 +361,7 @@ def __init__( self.configs = apis.AsyncConfigs(self) self.api_keys = apis.AsyncApiKeys(self) self.virtual_keys = apis.AsyncVirtualKeys(self) - self.logs=apis.AsyncLogs(self) + self.logs = apis.AsyncLogs(self) self.beta = self.beta(self) # type: ignore def copy( diff --git a/portkey_ai/api_resources/utils.py b/portkey_ai/api_resources/utils.py index 2ec77d0..dd2d0c1 100644 --- a/portkey_ai/api_resources/utils.py +++ b/portkey_ai/api_resources/utils.py @@ -122,7 +122,8 @@ class PortkeyApiPaths(str, Enum, metaclass=MetaEnum): CONFIG_API = "/configs" API_KEYS_API = "/api-keys" VIRTUAL_KEYS_API = "/virtual-keys" - LOGS_EXPORT_API = "/logs/exports" + LOGS_EXPORT_API = "/logs/exports" + class Options(BaseModel): method: str From ff38ce80bfa44d857f1d600478f9cffeba89a7dc Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Tue, 5 Nov 2024 15:41:48 +0530 Subject: [PATCH 6/6] fix: log export ret type --- portkey_ai/api_resources/types/logs_type.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/portkey_ai/api_resources/types/logs_type.py b/portkey_ai/api_resources/types/logs_type.py index 0b9f9f4..092fe39 100644 --- a/portkey_ai/api_resources/types/logs_type.py +++ b/portkey_ai/api_resources/types/logs_type.py @@ -1,6 +1,5 @@ import json from typing import Any, Dict, List, Optional -from datetime import datetime import httpx from pydantic import BaseModel, PrivateAttr from portkey_ai.api_resources.types.utils import parse_headers @@ -88,8 +87,8 @@ class LogsExportRetrieveResponse(BaseModel): requested_data: Optional[List[str]] status: Optional[str] description: Optional[str] - created_at: Optional[datetime] - last_updated_at: Optional[datetime] + created_at: Optional[str] + last_updated_at: Optional[str] created_by: Optional[str] workspace_id: Optional[str] total_records: Optional[int]