Skip to content
Merged
157 changes: 79 additions & 78 deletions portkey_ai/api_resources/apis/admin.py

Large diffs are not rendered by default.

89 changes: 45 additions & 44 deletions portkey_ai/api_resources/apis/api_keys.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Dict, List, Optional, Union
from portkey_ai._vendor.openai import NOT_GIVEN, NotGiven
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
Expand All @@ -18,17 +19,17 @@ def __init__(self, client: APIClient) -> None:
def create(
self,
*,
type: Optional[str] = None,
sub_type: Optional[str] = None,
name: Optional[str] = None,
description: Optional[str] = None,
workspace_id: Optional[str] = None,
user_id: Optional[str] = None,
rate_limits: Optional[List[Dict[str, Any]]] = None,
usage_limits: Optional[Dict[str, Any]] = None,
scopes: List[str],
defaults: Optional[Dict[str, Any]] = None,
expires_at: Optional[Any] = None,
type: Union[str, NotGiven] = NOT_GIVEN,
sub_type: Union[str, NotGiven] = NOT_GIVEN,
name: Union[str, NotGiven] = NOT_GIVEN,
description: Union[str, NotGiven] = NOT_GIVEN,
workspace_id: Union[str, NotGiven] = NOT_GIVEN,
user_id: Union[str, NotGiven] = NOT_GIVEN,
rate_limits: Union[List[Dict[str, Any]], NotGiven] = NOT_GIVEN,
usage_limits: Union[Dict[str, Any], NotGiven] = NOT_GIVEN,
scopes: Union[List[str], NotGiven] = NOT_GIVEN,
defaults: Union[Dict[str, Any], NotGiven] = NOT_GIVEN,
expires_at: Union[Any, NotGiven] = NOT_GIVEN,
**kwargs: Any,
) -> ApiKeyAddResponse:
body = {
Expand Down Expand Up @@ -69,16 +70,16 @@ def retrieve(self, *, id: Optional[str]) -> ApiKeyGetResponse:
def list(
self,
*,
page_size: Optional[Union[int, str]] = None,
page_size: Union[int, str, NotGiven] = NOT_GIVEN,
current_page: Optional[int] = 0,
workspace_id: Optional[str] = None,
workspace_id: Union[str, NotGiven] = NOT_GIVEN,
) -> ApiKeyListResponse:
query = {
"page_size": page_size,
"current_page": current_page,
"workspace_id": workspace_id,
}
filtered_query = {k: v for k, v in query.items() if v is not None}
filtered_query = {k: v for k, v in query.items() if v is not NOT_GIVEN}
query_string = urlencode(filtered_query)
return self._get(
f"{PortkeyApiPaths.API_KEYS_API}?{query_string}",
Expand All @@ -93,14 +94,14 @@ def list(
def update(
self,
*,
id: Optional[str] = None,
name: Optional[str] = None,
description: Optional[str] = None,
rate_limits: Optional[List[Dict[str, Any]]] = None,
usage_limits: Optional[Dict[str, Any]] = None,
scopes: Optional[List[str]] = None,
defaults: Optional[Dict[str, Any]] = None,
expires_at: Optional[Any] = None,
id: Union[str, NotGiven] = NOT_GIVEN,
name: Union[str, NotGiven] = NOT_GIVEN,
description: Union[str, NotGiven] = NOT_GIVEN,
rate_limits: Union[List[Dict[str, Any]], NotGiven] = NOT_GIVEN,
usage_limits: Union[Dict[str, Any], NotGiven] = NOT_GIVEN,
scopes: Union[List[str], NotGiven] = NOT_GIVEN,
defaults: Union[Dict[str, Any], NotGiven] = NOT_GIVEN,
expires_at: Union[Any, NotGiven] = NOT_GIVEN,
**kwargs: Any,
) -> Any:
body = {
Expand Down Expand Up @@ -147,17 +148,17 @@ def __init__(self, client: AsyncAPIClient) -> None:
async def create(
self,
*,
type: Optional[str] = None,
sub_type: Optional[str] = None,
name: Optional[str] = None,
description: Optional[str] = None,
workspace_id: Optional[str] = None,
user_id: Optional[str] = None,
rate_limits: Optional[List[Dict[str, Any]]] = None,
usage_limits: Optional[Dict[str, Any]] = None,
scopes: List[str],
defaults: Optional[Dict[str, Any]] = None,
expires_at: Optional[Any] = None,
type: Union[str, NotGiven] = NOT_GIVEN,
sub_type: Union[str, NotGiven] = NOT_GIVEN,
name: Union[str, NotGiven] = NOT_GIVEN,
description: Union[str, NotGiven] = NOT_GIVEN,
workspace_id: Union[str, NotGiven] = NOT_GIVEN,
user_id: Union[str, NotGiven] = NOT_GIVEN,
rate_limits: Union[List[Dict[str, Any]], NotGiven] = NOT_GIVEN,
usage_limits: Union[Dict[str, Any], NotGiven] = NOT_GIVEN,
scopes: Union[List[str], NotGiven] = NOT_GIVEN,
defaults: Union[Dict[str, Any], NotGiven] = NOT_GIVEN,
expires_at: Union[Any, NotGiven] = NOT_GIVEN,
**kwargs: Any,
) -> ApiKeyAddResponse:
body = {
Expand Down Expand Up @@ -198,16 +199,16 @@ async def retrieve(self, *, id: Optional[str]) -> ApiKeyGetResponse:
async def list(
self,
*,
page_size: Optional[Union[int, str]] = None,
page_size: Union[int, str, NotGiven] = NOT_GIVEN,
current_page: Optional[int] = 0,
workspace_id: Optional[str] = None,
workspace_id: Union[str, NotGiven] = NOT_GIVEN,
) -> ApiKeyListResponse:
query = {
"page_size": page_size,
"current_page": current_page,
"workspace_id": workspace_id,
}
filtered_query = {k: v for k, v in query.items() if v is not None}
filtered_query = {k: v for k, v in query.items() if v is not NOT_GIVEN}
query_string = urlencode(filtered_query)
return await self._get(
f"{PortkeyApiPaths.API_KEYS_API}?{query_string}",
Expand All @@ -222,14 +223,14 @@ async def list(
async def update(
self,
*,
id: Optional[str] = None,
name: Optional[str] = None,
description: Optional[str] = None,
rate_limits: Optional[List[Dict[str, Any]]] = None,
usage_limits: Optional[Dict[str, Any]] = None,
scopes: Optional[List[str]] = None,
defaults: Optional[Dict[str, Any]] = None,
expires_at: Optional[Any] = None,
id: Union[str, NotGiven] = NOT_GIVEN,
name: Union[str, NotGiven] = NOT_GIVEN,
description: Union[str, NotGiven] = NOT_GIVEN,
rate_limits: Union[List[Dict[str, Any]], NotGiven] = NOT_GIVEN,
usage_limits: Union[Dict[str, Any], NotGiven] = NOT_GIVEN,
scopes: Union[List[str], NotGiven] = NOT_GIVEN,
defaults: Union[Dict[str, Any], NotGiven] = NOT_GIVEN,
expires_at: Union[Any, NotGiven] = NOT_GIVEN,
**kwargs: Any,
) -> Any:
body = {
Expand Down
35 changes: 18 additions & 17 deletions portkey_ai/api_resources/apis/collections.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, Optional
from typing import Any, Union
from urllib.parse import urlencode
from portkey_ai._vendor.openai import NOT_GIVEN, NotGiven
from portkey_ai.api_resources.apis.api_resource import APIResource, AsyncAPIResource
from portkey_ai.api_resources.base_client import APIClient, AsyncAPIClient
from portkey_ai.api_resources.utils import GenericResponse, PortkeyApiPaths
Expand All @@ -12,8 +13,8 @@ def __init__(self, client: APIClient) -> None:
def create(
self,
name: str,
workspace_id: Optional[str] = None,
parent_collection_id: Optional[str] = None,
workspace_id: Union[str, NotGiven] = NOT_GIVEN,
parent_collection_id: Union[str, NotGiven] = NOT_GIVEN,
) -> Any:
body = {
"name": name,
Expand All @@ -33,18 +34,18 @@ def create(
def list(
self,
*,
workspace_id: Optional[str] = None,
current_page: Optional[int] = None,
page_size: Optional[int] = None,
search: Optional[str] = None,
workspace_id: Union[str, NotGiven] = NOT_GIVEN,
current_page: Union[int, NotGiven] = NOT_GIVEN,
page_size: Union[int, NotGiven] = NOT_GIVEN,
search: Union[str, NotGiven] = NOT_GIVEN,
) -> Any:
query = {
"workspace_id": workspace_id,
"current_page": current_page,
"page_size": page_size,
"search": search,
}
filtered_query = {k: v for k, v in query.items() if v is not None}
filtered_query = {k: v for k, v in query.items() if v is not NOT_GIVEN}
query_string = urlencode(filtered_query)
return self._get(
f"{PortkeyApiPaths.COLLECTIONS_API}?{query_string}",
Expand Down Expand Up @@ -74,7 +75,7 @@ def update(
self,
collection_id: str,
*,
name: Optional[str] = None,
name: Union[str, NotGiven] = NOT_GIVEN,
) -> Any:
body = {
"name": name,
Expand Down Expand Up @@ -111,8 +112,8 @@ def __init__(self, client: AsyncAPIClient) -> None:
async def create(
self,
name: str,
workspace_id: Optional[str] = None,
parent_collection_id: Optional[str] = None,
workspace_id: Union[str, NotGiven] = NOT_GIVEN,
parent_collection_id: Union[str, NotGiven] = NOT_GIVEN,
) -> Any:
body = {
"name": name,
Expand All @@ -132,18 +133,18 @@ async def create(
async def list(
self,
*,
workspace_id: Optional[str] = None,
current_page: Optional[int] = None,
page_size: Optional[int] = None,
search: Optional[str] = None,
workspace_id: Union[str, NotGiven] = NOT_GIVEN,
current_page: Union[int, NotGiven] = NOT_GIVEN,
page_size: Union[int, NotGiven] = NOT_GIVEN,
search: Union[str, NotGiven] = NOT_GIVEN,
) -> Any:
query = {
"workspace_id": workspace_id,
"current_page": current_page,
"page_size": page_size,
"search": search,
}
filtered_query = {k: v for k, v in query.items() if v is not None}
filtered_query = {k: v for k, v in query.items() if v is not NOT_GIVEN}
query_string = urlencode(filtered_query)
return await self._get(
f"{PortkeyApiPaths.COLLECTIONS_API}?{query_string}",
Expand Down Expand Up @@ -173,7 +174,7 @@ async def update(
self,
collection_id: str,
*,
name: Optional[str] = None,
name: Union[str, NotGiven] = NOT_GIVEN,
) -> Any:
body = {
"name": name,
Expand Down
54 changes: 30 additions & 24 deletions portkey_ai/api_resources/apis/configs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Dict, Optional
from typing import Any, Dict, Optional, Union
from portkey_ai._vendor.openai import NOT_GIVEN, NotGiven
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
Expand All @@ -19,10 +20,10 @@ def __init__(self, client: APIClient) -> None:
def create(
self,
*,
name: Optional[str] = None,
config: Optional[Dict[str, Any]] = None,
is_default: Optional[int] = None,
workspace_id: Optional[str] = None,
name: Union[str, NotGiven] = NOT_GIVEN,
config: Union[Dict[str, Any], NotGiven] = NOT_GIVEN,
is_default: Union[int, NotGiven] = NOT_GIVEN,
workspace_id: Union[str, NotGiven] = NOT_GIVEN,
) -> ConfigAddResponse:
body = {
"name": name,
Expand Down Expand Up @@ -54,12 +55,12 @@ def retrieve(self, *, slug: Optional[str]) -> ConfigGetResponse:
def list(
self,
*,
workspace_id: Optional[str] = None,
workspace_id: Union[str, NotGiven] = NOT_GIVEN,
) -> ConfigListResponse:
query = {
"workspace_id": workspace_id,
}
filtered_query = {k: v for k, v in query.items() if v is not None}
filtered_query = {k: v for k, v in query.items() if v is not NOT_GIVEN}
query_string = urlencode(filtered_query)
return self._get(
f"{PortkeyApiPaths.CONFIG_API}?{query_string}",
Expand All @@ -74,10 +75,10 @@ def list(
def update(
self,
*,
slug: Optional[str] = None,
name: Optional[str] = None,
config: Optional[Dict[str, Any]] = None,
status: Optional[str] = None,
slug: Union[str, NotGiven] = NOT_GIVEN,
name: Union[str, NotGiven] = NOT_GIVEN,
config: Union[Dict[str, Any], NotGiven] = NOT_GIVEN,
status: Union[str, NotGiven] = NOT_GIVEN,
) -> ConfigUpdateResponse:
body = {
"slug": slug,
Expand All @@ -95,7 +96,12 @@ def update(
headers={},
)

def delete(self, *, id: Optional[str] = None, slug: Optional[str] = None) -> Any:
def delete(
self,
*,
id: Union[str, NotGiven] = NOT_GIVEN,
slug: Union[str, NotGiven] = NOT_GIVEN,
) -> Any:
config_slug = None
if id:
import warnings
Expand Down Expand Up @@ -128,10 +134,10 @@ def __init__(self, client: AsyncAPIClient) -> None:
async def create(
self,
*,
name: Optional[str] = None,
config: Optional[Dict[str, Any]] = None,
is_default: Optional[int] = None,
workspace_id: Optional[str] = None,
name: Union[str, NotGiven] = NOT_GIVEN,
config: Union[Dict[str, Any], NotGiven] = NOT_GIVEN,
is_default: Union[int, NotGiven] = NOT_GIVEN,
workspace_id: Union[str, NotGiven] = NOT_GIVEN,
) -> ConfigAddResponse:
body = {
"name": name,
Expand Down Expand Up @@ -163,12 +169,12 @@ async def retrieve(self, *, slug: Optional[str]) -> ConfigGetResponse:
async def list(
self,
*,
workspace_id: Optional[str] = None,
workspace_id: Union[str, NotGiven] = NOT_GIVEN,
) -> ConfigListResponse:
query = {
"workspace_id": workspace_id,
}
filtered_query = {k: v for k, v in query.items() if v is not None}
filtered_query = {k: v for k, v in query.items() if v is not NOT_GIVEN}
query_string = urlencode(filtered_query)
return await self._get(
f"{PortkeyApiPaths.CONFIG_API}?{query_string}",
Expand All @@ -183,10 +189,10 @@ async def list(
async def update(
self,
*,
slug: Optional[str] = None,
name: Optional[str] = None,
config: Optional[Dict[str, Any]] = None,
status: Optional[str] = None,
slug: Union[str, NotGiven] = NOT_GIVEN,
name: Union[str, NotGiven] = NOT_GIVEN,
config: Union[Dict[str, Any], NotGiven] = NOT_GIVEN,
status: Union[str, NotGiven] = NOT_GIVEN,
) -> ConfigUpdateResponse:
body = {
"slug": slug,
Expand All @@ -207,8 +213,8 @@ async def update(
async def delete(
self,
*,
id: Optional[str] = None,
slug: Optional[str] = None,
id: Union[str, NotGiven] = NOT_GIVEN,
slug: Union[str, NotGiven] = NOT_GIVEN,
) -> Any:
config_slug = None
if id:
Expand Down
Loading