Skip to content

Commit

Permalink
feat: insert log supported
Browse files Browse the repository at this point in the history
  • Loading branch information
csgulati09 committed Dec 7, 2024
1 parent d510508 commit a566175
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
45 changes: 45 additions & 0 deletions portkey_ai/api_resources/apis/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ def __init__(self, client: APIClient) -> None:
super().__init__(client)
self.exports = Exports(client)

def create(
self,
*,
request: Optional[Dict[str, Any]] = None,
response: Optional[Dict[str, Any]] = None,
metadata: Optional[Dict[str, Any]] = None,
) -> Any:
body = {
"request": request,
"response": response,
"metadata": metadata,
}
response = self._post(
f"{PortkeyApiPaths.LOGS_API}",
body=body,
params=None,
cast_to=None,
stream=False,
stream_cls=None,
headers={},
)
return response


class Exports(APIResource):
def __init__(self, client: APIClient) -> None:
Expand Down Expand Up @@ -153,6 +176,28 @@ def __init__(self, client: AsyncAPIClient) -> None:
super().__init__(client)
self.exports = AsyncExports(client)

async def create(
self,
*,
request: Optional[Dict[str, Any]] = None,
response: Optional[Dict[str, Any]] = None,
metadata: Optional[Dict[str, Any]] = None,
) -> Any:
body = {
"request": request,
"response": response,
"metadata": metadata,
}
return await self._post(
f"{PortkeyApiPaths.LOGS_API}",
body=body,
params=None,
cast_to=None,
stream=False,
stream_cls=None,
headers={},
)


class AsyncExports(AsyncAPIResource):
def __init__(self, client: AsyncAPIClient) -> None:
Expand Down
6 changes: 6 additions & 0 deletions portkey_ai/api_resources/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,9 @@ def _request(
)
return stream_response

if not cast_to:
return res # type: ignore [return-value]

response = (
cast(
ResponseT,
Expand Down Expand Up @@ -1279,6 +1282,9 @@ async def _request(
)
return stream_response

if not cast_to:
return res # type: ignore [return-value]

response = (
cast(
ResponseT,
Expand Down
1 change: 1 addition & 0 deletions portkey_ai/api_resources/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class PortkeyApiPaths(str, Enum, metaclass=MetaEnum):
API_KEYS_API = "/api-keys"
VIRTUAL_KEYS_API = "/virtual-keys"
LOGS_EXPORT_API = "/logs/exports"
LOGS_API = "/logs"


class Options(BaseModel):
Expand Down

0 comments on commit a566175

Please sign in to comment.