Skip to content

Commit 3419dcd

Browse files
committed
feat: integrations support added
1 parent f6c935a commit 3419dcd

6 files changed

Lines changed: 263 additions & 0 deletions

File tree

portkey_ai/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@
123123
AsyncContainersFiles,
124124
Content,
125125
AsyncContent,
126+
Integrations,
127+
AsyncIntegrations,
126128
)
127129

128130
from portkey_ai.version import VERSION
@@ -265,4 +267,6 @@
265267
"AsyncContainersFiles",
266268
"Content",
267269
"AsyncContent",
270+
"Integrations",
271+
"AsyncIntegrations",
268272
]

portkey_ai/api_resources/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@
111111
AsyncContainersFiles,
112112
Content,
113113
AsyncContent,
114+
Integrations,
115+
AsyncIntegrations,
114116
)
115117
from .utils import (
116118
Modes,
@@ -257,4 +259,6 @@
257259
"AsyncContainersFiles",
258260
"Content",
259261
"AsyncContent",
262+
"Integrations",
263+
"AsyncIntegrations",
260264
]

portkey_ai/api_resources/apis/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@
139139

140140
from .collections import Collections, AsyncCollections
141141

142+
from .integrations import Integrations, AsyncIntegrations
143+
142144
sys.modules["openai"] = vendored_openai # For pydantic v1 and v2 compatibility
143145

144146
__all__ = [
@@ -263,4 +265,6 @@
263265
"AsyncContainersFiles",
264266
"Content",
265267
"AsyncContent",
268+
"Integrations",
269+
"AsyncIntegrations",
266270
]
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
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 Integrations(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.INTEGRATIONS_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.INTEGRATIONS_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.INTEGRATIONS_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.INTEGRATIONS_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.INTEGRATIONS_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 AsyncIntegrations(AsyncAPIResource):
130+
def __init__(self, client: AsyncAPIClient) -> None:
131+
super().__init__(client)
132+
133+
async def create(
134+
self,
135+
*,
136+
name: Optional[str] = None,
137+
description: Optional[str] = None,
138+
key: Optional[str] = None,
139+
ai_provider_id: Optional[str] = None,
140+
workspace_id: Optional[str] = None,
141+
slug: Optional[str] = None,
142+
organisation_id: Optional[str] = None,
143+
note: Optional[str] = None,
144+
configuration: Optional[Dict[str, Any]] = None,
145+
**kwargs: Any,
146+
) -> GenericResponse:
147+
body = {
148+
"name": name,
149+
"description": description,
150+
"key": key,
151+
"ai_provider_id": ai_provider_id,
152+
"workspace_id": workspace_id,
153+
"slug": slug,
154+
"organisation_id": organisation_id,
155+
"note": note,
156+
"configuration": configuration,
157+
**kwargs,
158+
}
159+
return await self._post(
160+
f"{PortkeyApiPaths.INTEGRATIONS_API}",
161+
body=body,
162+
params=None,
163+
cast_to=GenericResponse,
164+
stream=False,
165+
stream_cls=None,
166+
headers={},
167+
)
168+
169+
async def list(
170+
self,
171+
*,
172+
organisation_id: Optional[str] = None,
173+
workspace_id: Optional[str] = None,
174+
current_page: Optional[int] = None,
175+
page_size: Optional[int] = None,
176+
) -> GenericResponse:
177+
query = {
178+
"organisation_id": organisation_id,
179+
"workspace_id": workspace_id,
180+
"current_page": current_page,
181+
"page_size": page_size,
182+
}
183+
filtered_query = {k: v for k, v in query.items() if v is not None}
184+
query_string = urlencode(filtered_query)
185+
return await self._get(
186+
f"{PortkeyApiPaths.INTEGRATIONS_API}?{query_string}",
187+
params=None,
188+
body=None,
189+
cast_to=GenericResponse,
190+
stream=False,
191+
stream_cls=None,
192+
headers={},
193+
)
194+
195+
async def retrieve(self, *, integration_id: Optional[str]) -> Any:
196+
return await self._get(
197+
f"{PortkeyApiPaths.INTEGRATIONS_API}/{integration_id}",
198+
params=None,
199+
body=None,
200+
cast_to=GenericResponse,
201+
stream=False,
202+
stream_cls=None,
203+
headers={},
204+
)
205+
206+
async def update(
207+
self,
208+
*,
209+
integration_id: Optional[str] = None,
210+
name: Optional[str] = None,
211+
description: Optional[str] = None,
212+
key: Optional[str] = None,
213+
configuration: Optional[Dict[str, Any]] = None,
214+
**kwargs: Any,
215+
) -> GenericResponse:
216+
body = {
217+
"name": name,
218+
"description": description,
219+
"key": key,
220+
"configuration": configuration,
221+
**kwargs,
222+
}
223+
return await self._put(
224+
f"{PortkeyApiPaths.INTEGRATIONS_API}/{integration_id}",
225+
body=body,
226+
params=None,
227+
cast_to=GenericResponse,
228+
stream=False,
229+
stream_cls=None,
230+
headers={},
231+
)
232+
233+
async def delete(
234+
self,
235+
*,
236+
integration_id: Optional[str],
237+
) -> Any:
238+
return await self._delete(
239+
f"{PortkeyApiPaths.INTEGRATIONS_API}/{integration_id}",
240+
params=None,
241+
body=None,
242+
cast_to=GenericResponse,
243+
stream=False,
244+
stream_cls=None,
245+
headers={},
246+
)

portkey_ai/api_resources/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Portkey(APIClient):
3535
logs: apis.Logs
3636
labels: apis.Labels
3737
collections: apis.Collections
38+
integrations: apis.Integrations
3839

3940
class beta:
4041
assistants: apis.Assistants
@@ -175,6 +176,7 @@ def __init__(
175176
self.logs = apis.Logs(self)
176177
self.labels = apis.Labels(self)
177178
self.collections = apis.Collections(self)
179+
self.integrations = apis.Integrations(self)
178180
self.beta = self.beta(self) # type: ignore
179181

180182
if self.instrumentation:
@@ -352,6 +354,7 @@ class AsyncPortkey(AsyncAPIClient):
352354
logs: apis.AsyncLogs
353355
labels: apis.AsyncLabels
354356
collections: apis.AsyncCollections
357+
integrations: apis.AsyncIntegrations
355358

356359
class beta:
357360
assistants: apis.AsyncAssistants
@@ -492,6 +495,7 @@ def __init__(
492495
self.logs = apis.AsyncLogs(self)
493496
self.labels = apis.AsyncLabels(self)
494497
self.collections = apis.AsyncCollections(self)
498+
self.integrations = apis.AsyncIntegrations(self)
495499
self.beta = self.beta(self) # type: ignore
496500

497501
if self.instrumentation:

portkey_ai/api_resources/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class PortkeyApiPaths(str, Enum, metaclass=MetaEnum):
129129
COLLECTIONS_API = "/collections"
130130
PROMPTS_API = "/prompts"
131131
PROMPTS_PARTIALS_API = "/prompts/partials"
132+
INTEGRATIONS_API = "/integrations"
132133

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

0 commit comments

Comments
 (0)