Skip to content

Commit df3cc23

Browse files
committed
feat: WIP: provider support
1 parent 204e313 commit df3cc23

6 files changed

Lines changed: 148 additions & 0 deletions

File tree

portkey_ai/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@
129129
AsyncIntegrationsWorkspaces,
130130
IntegrationsModels,
131131
AsyncIntegrationsModels,
132+
Providers,
133+
AsyncProviders,
132134
)
133135

134136
from portkey_ai.version import VERSION
@@ -277,4 +279,6 @@
277279
"AsyncIntegrationsWorkspaces",
278280
"IntegrationsModels",
279281
"AsyncIntegrationsModels",
282+
"Providers",
283+
"AsyncProviders",
280284
]

portkey_ai/api_resources/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@
117117
AsyncIntegrationsWorkspaces,
118118
IntegrationsModels,
119119
AsyncIntegrationsModels,
120+
Providers,
121+
AsyncProviders,
120122
)
121123
from .utils import (
122124
Modes,
@@ -269,4 +271,6 @@
269271
"AsyncIntegrationsWorkspaces",
270272
"IntegrationsModels",
271273
"AsyncIntegrationsModels",
274+
"Providers",
275+
"AsyncProviders",
272276
]

portkey_ai/api_resources/apis/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@
148148
AsyncIntegrationsModels,
149149
)
150150

151+
from .providers import Providers, AsyncProviders
152+
151153
sys.modules["openai"] = vendored_openai # For pydantic v1 and v2 compatibility
152154

153155
__all__ = [
@@ -278,4 +280,6 @@
278280
"AsyncIntegrationsWorkspaces",
279281
"IntegrationsModels",
280282
"AsyncIntegrationsModels",
283+
"Providers",
284+
"AsyncProviders",
281285
]
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
from typing import Any, Dict, Optional
2+
from portkey_ai.api_resources.base_client import APIClient, AsyncAPIClient
3+
from urllib.parse import urlencode
4+
from portkey_ai.api_resources.apis.api_resource import APIResource, AsyncAPIResource
5+
from portkey_ai.api_resources.utils import GenericResponse
6+
from portkey_ai.api_resources.utils import PortkeyApiPaths
7+
8+
9+
class Providers(APIResource):
10+
def __init__(self, client: APIClient) -> None:
11+
super().__init__(client)
12+
13+
def create(
14+
self,
15+
*,
16+
name: Optional[str] = None,
17+
description: Optional[str] = None,
18+
key: Optional[str] = None,
19+
ai_provider_id: Optional[str] = None,
20+
workspace_id: Optional[str] = None,
21+
slug: Optional[str] = None,
22+
organisation_id: Optional[str] = None,
23+
note: Optional[str] = None,
24+
configuration: Optional[Dict[str, Any]] = None,
25+
**kwargs: Any,
26+
) -> GenericResponse:
27+
body = {
28+
"name": name,
29+
"description": description,
30+
"key": key,
31+
"ai_provider_id": ai_provider_id,
32+
"workspace_id": workspace_id,
33+
"slug": slug,
34+
"organisation_id": organisation_id,
35+
"note": note,
36+
"configuration": configuration,
37+
**kwargs,
38+
}
39+
return self._post(
40+
f"{PortkeyApiPaths.PROVIDERS_API}",
41+
body=body,
42+
params=None,
43+
cast_to=GenericResponse,
44+
stream=False,
45+
stream_cls=None,
46+
headers={},
47+
)
48+
49+
def list(
50+
self,
51+
*,
52+
organisation_id: Optional[str] = None,
53+
workspace_id: Optional[str] = None,
54+
current_page: Optional[int] = None,
55+
page_size: Optional[int] = None,
56+
) -> GenericResponse:
57+
query = {
58+
"organisation_id": organisation_id,
59+
"workspace_id": workspace_id,
60+
"current_page": current_page,
61+
"page_size": page_size,
62+
}
63+
filtered_query = {k: v for k, v in query.items() if v is not None}
64+
query_string = urlencode(filtered_query)
65+
return self._get(
66+
f"{PortkeyApiPaths.PROVIDERS_API}?{query_string}",
67+
params=None,
68+
body=None,
69+
cast_to=GenericResponse,
70+
stream=False,
71+
stream_cls=None,
72+
headers={},
73+
)
74+
75+
def retrieve(self, *, integration_id: Optional[str]) -> Any:
76+
return self._get(
77+
f"{PortkeyApiPaths.PROVIDERS_API}/{integration_id}",
78+
params=None,
79+
body=None,
80+
cast_to=GenericResponse,
81+
stream=False,
82+
stream_cls=None,
83+
headers={},
84+
)
85+
86+
def update(
87+
self,
88+
*,
89+
integration_id: Optional[str] = None,
90+
name: Optional[str] = None,
91+
description: Optional[str] = None,
92+
key: Optional[str] = None,
93+
configuration: Optional[Dict[str, Any]] = None,
94+
**kwargs: Any,
95+
) -> GenericResponse:
96+
body = {
97+
"name": name,
98+
"description": description,
99+
"key": key,
100+
"configuration": configuration,
101+
**kwargs,
102+
}
103+
return self._put(
104+
f"{PortkeyApiPaths.PROVIDERS_API}/{integration_id}",
105+
body=body,
106+
params=None,
107+
cast_to=GenericResponse,
108+
stream=False,
109+
stream_cls=None,
110+
headers={},
111+
)
112+
113+
def delete(
114+
self,
115+
*,
116+
integration_id: Optional[str],
117+
) -> Any:
118+
return self._delete(
119+
f"{PortkeyApiPaths.PROVIDERS_API}/{integration_id}",
120+
params=None,
121+
body=None,
122+
cast_to=GenericResponse,
123+
stream=False,
124+
stream_cls=None,
125+
headers={},
126+
)
127+
128+
129+
class AsyncProviders(AsyncAPIResource):
130+
def __init__(self, client: AsyncAPIClient) -> None:
131+
super().__init__(client)

portkey_ai/api_resources/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Portkey(APIClient):
3636
labels: apis.Labels
3737
collections: apis.Collections
3838
integrations: apis.Integrations
39+
providers: apis.Providers
3940

4041
class beta:
4142
assistants: apis.Assistants
@@ -177,6 +178,7 @@ def __init__(
177178
self.labels = apis.Labels(self)
178179
self.collections = apis.Collections(self)
179180
self.integrations = apis.Integrations(self)
181+
self.providers = apis.Providers(self)
180182
self.beta = self.beta(self) # type: ignore
181183

182184
if self.instrumentation:
@@ -355,6 +357,7 @@ class AsyncPortkey(AsyncAPIClient):
355357
labels: apis.AsyncLabels
356358
collections: apis.AsyncCollections
357359
integrations: apis.AsyncIntegrations
360+
providers: apis.AsyncProviders
358361

359362
class beta:
360363
assistants: apis.AsyncAssistants
@@ -496,6 +499,7 @@ def __init__(
496499
self.labels = apis.AsyncLabels(self)
497500
self.collections = apis.AsyncCollections(self)
498501
self.integrations = apis.AsyncIntegrations(self)
502+
self.providers = apis.AsyncProviders(self)
499503
self.beta = self.beta(self) # type: ignore
500504

501505
if self.instrumentation:

portkey_ai/api_resources/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class PortkeyApiPaths(str, Enum, metaclass=MetaEnum):
130130
PROMPTS_API = "/prompts"
131131
PROMPTS_PARTIALS_API = "/prompts/partials"
132132
INTEGRATIONS_API = "/integrations"
133+
PROVIDERS_API = "/providers"
133134

134135
def __str__(self):
135136
return self.value

0 commit comments

Comments
 (0)