Skip to content

Commit

Permalink
Merge pull request #236 from Portkey-AI/feat/logsExport
Browse files Browse the repository at this point in the history
feat: logs-exports api
  • Loading branch information
csgulati09 authored Nov 7, 2024
2 parents 3ba9486 + ff38ce8 commit fda4d1a
Show file tree
Hide file tree
Showing 7 changed files with 441 additions and 0 deletions.
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",
]
3 changes: 3 additions & 0 deletions portkey_ai/api_resources/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

from .api_keys import ApiKeys, AsyncApiKeys
from .virtual_keys import VirtualKeys, AsyncVirtualKeys
from .logs import Logs, AsyncLogs

__all__ = [
"Completion",
Expand Down Expand Up @@ -159,4 +160,6 @@
"AsyncApiKeys",
"VirtualKeys",
"AsyncVirtualKeys",
"Logs",
"AsyncLogs",
]
282 changes: 282 additions & 0 deletions portkey_ai/api_resources/apis/logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
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: apis.Logs

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 = apis.Logs(self)
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: apis.AsyncLogs

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

0 comments on commit fda4d1a

Please sign in to comment.