Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: logs-exports api #236

Merged
merged 9 commits into from
Nov 7, 2024
Merged
4 changes: 4 additions & 0 deletions portkey_ai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
AsyncApiKeys,
VirtualKeys,
AsyncVirtualKeys,
Logs,
AsyncLogs,
)

from portkey_ai.version import VERSION
Expand Down Expand Up @@ -193,4 +195,6 @@
"AsyncApiKeys",
"VirtualKeys",
"AsyncVirtualKeys",
"Logs",
"AsyncLogs"
]
4 changes: 4 additions & 0 deletions portkey_ai/api_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
AsyncApiKeys,
VirtualKeys,
AsyncVirtualKeys,
Logs,
AsyncLogs,
)
from .utils import (
Modes,
Expand Down Expand Up @@ -185,4 +187,6 @@
"AsyncApiKeys",
"VirtualKeys",
"AsyncVirtualKeys",
"Logs",
"AsyncLogs"
]
4 changes: 3 additions & 1 deletion portkey_ai/api_resources/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

from .api_keys import ApiKeys, AsyncApiKeys
from .virtual_keys import VirtualKeys, AsyncVirtualKeys

from .logs import Logs, AsyncLogs
__all__ = [
"Completion",
"AsyncCompletion",
Expand Down Expand Up @@ -159,4 +159,6 @@
"AsyncApiKeys",
"VirtualKeys",
"AsyncVirtualKeys",
"Logs",
"AsyncLogs"
]
280 changes: 280 additions & 0 deletions portkey_ai/api_resources/apis/logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
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_type import (
LogsExportCreateResponse,
LogsExportListResponse,
LogsExportUpdateResponse,
LogsExportCancelResponse,
LogsExportRetrieveResponse,
LogsExportStartResponse,
LogsExportDownloadResponse,
)
from portkey_ai.api_resources.utils import PortkeyApiPaths


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)

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, *, export_id: str) -> LogsExportRetrieveResponse:
return self._get(
f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}",
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,
*,
export_id: 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}/{export_id}",
body=body,
params=None,
cast_to=LogsExportUpdateResponse,
stream=False,
stream_cls=None,
headers={},
)

def start(
self,
*,
export_id: Optional[str],
) -> LogsExportStartResponse:
return self._post(
f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}/start",
body=None,
params=None,
cast_to=LogsExportStartResponse,
stream=False,
stream_cls=None,
headers={},
)

def cancel(
self,
*,
export_id: Optional[str],
) -> LogsExportCancelResponse:
return self._post(
f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}/cancel",
body=None,
params=None,
cast_to=LogsExportCancelResponse,
stream=False,
stream_cls=None,
headers={},
)

def download(
self,
*,
export_id: Optional[str],
) -> LogsExportDownloadResponse:
return self._get(
f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}/download",
params=None,
body=None,
cast_to=LogsExportDownloadResponse,
stream=False,
stream_cls=None,
headers={},
)


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)

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, *, export_id: str) -> LogsExportRetrieveResponse:
return await self._get(
f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}",
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,
*,
export_id: 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}/{export_id}",
body=body,
params=None,
cast_to=LogsExportUpdateResponse,
stream=False,
stream_cls=None,
headers={},
)

async def start(
self,
*,
export_id: Optional[str],
) -> LogsExportStartResponse:
return await self._post(
f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}/start",
body=None,
params=None,
cast_to=LogsExportStartResponse,
stream=False,
stream_cls=None,
headers={},
)

async def cancel(
self,
*,
export_id: Optional[str],
) -> LogsExportCancelResponse:
return await self._post(
f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}/cancel",
body=None,
params=None,
cast_to=LogsExportCancelResponse,
stream=False,
stream_cls=None,
headers={},
)

async def download(
self,
*,
export_id: Optional[str],
) -> LogsExportDownloadResponse:
return await self._get(
f"{PortkeyApiPaths.LOGS_EXPORT_API}/{export_id}/download",
params=None,
body=None,
cast_to=LogsExportDownloadResponse,
stream=False,
stream_cls=None,
headers={},
)
4 changes: 4 additions & 0 deletions portkey_ai/api_resources/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +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
Expand Down Expand Up @@ -143,6 +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)
csgulati09 marked this conversation as resolved.
Show resolved Hide resolved
self.beta = self.beta(self) # type: ignore

def copy(
Expand Down Expand Up @@ -246,6 +248,7 @@ class AsyncPortkey(AsyncAPIClient):
configs: apis.AsyncConfigs
api_keys: apis.AsyncApiKeys
virtual_keys: apis.AsyncVirtualKeys
logs_export: apis.AsyncLogsExport
csgulati09 marked this conversation as resolved.
Show resolved Hide resolved

class beta:
assistants: apis.AsyncAssistants
Expand Down Expand Up @@ -358,6 +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.beta = self.beta(self) # type: ignore

def copy(
Expand Down
Loading
Loading