diff --git a/portkey_ai/__init__.py b/portkey_ai/__init__.py index b165056..9f65583 100644 --- a/portkey_ai/__init__.py +++ b/portkey_ai/__init__.py @@ -123,6 +123,12 @@ AsyncContainersFiles, Content, AsyncContent, + Integrations, + AsyncIntegrations, + IntegrationsWorkspaces, + AsyncIntegrationsWorkspaces, + IntegrationsModels, + AsyncIntegrationsModels, ) from portkey_ai.version import VERSION @@ -265,4 +271,10 @@ "AsyncContainersFiles", "Content", "AsyncContent", + "Integrations", + "AsyncIntegrations", + "IntegrationsWorkspaces", + "AsyncIntegrationsWorkspaces", + "IntegrationsModels", + "AsyncIntegrationsModels", ] diff --git a/portkey_ai/api_resources/__init__.py b/portkey_ai/api_resources/__init__.py index cb2716d..be4441b 100644 --- a/portkey_ai/api_resources/__init__.py +++ b/portkey_ai/api_resources/__init__.py @@ -111,6 +111,12 @@ AsyncContainersFiles, Content, AsyncContent, + Integrations, + AsyncIntegrations, + IntegrationsWorkspaces, + AsyncIntegrationsWorkspaces, + IntegrationsModels, + AsyncIntegrationsModels, ) from .utils import ( Modes, @@ -257,4 +263,10 @@ "AsyncContainersFiles", "Content", "AsyncContent", + "Integrations", + "AsyncIntegrations", + "IntegrationsWorkspaces", + "AsyncIntegrationsWorkspaces", + "IntegrationsModels", + "AsyncIntegrationsModels", ] diff --git a/portkey_ai/api_resources/apis/__init__.py b/portkey_ai/api_resources/apis/__init__.py index 92b9ff4..b29f274 100644 --- a/portkey_ai/api_resources/apis/__init__.py +++ b/portkey_ai/api_resources/apis/__init__.py @@ -139,6 +139,15 @@ from .collections import Collections, AsyncCollections +from .integrations import ( + Integrations, + AsyncIntegrations, + IntegrationsWorkspaces, + AsyncIntegrationsWorkspaces, + IntegrationsModels, + AsyncIntegrationsModels, +) + sys.modules["openai"] = vendored_openai # For pydantic v1 and v2 compatibility __all__ = [ @@ -263,4 +272,10 @@ "AsyncContainersFiles", "Content", "AsyncContent", + "Integrations", + "AsyncIntegrations", + "IntegrationsWorkspaces", + "AsyncIntegrationsWorkspaces", + "IntegrationsModels", + "AsyncIntegrationsModels", ] diff --git a/portkey_ai/api_resources/apis/integrations.py b/portkey_ai/api_resources/apis/integrations.py new file mode 100644 index 0000000..5ba910e --- /dev/null +++ b/portkey_ai/api_resources/apis/integrations.py @@ -0,0 +1,430 @@ +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.utils import GenericResponse +from portkey_ai.api_resources.utils import PortkeyApiPaths + + +class Integrations(APIResource): + def __init__(self, client: APIClient) -> None: + super().__init__(client) + self.workspaces = IntegrationsWorkspaces(client) + self.models = IntegrationsModels(client) + + def create( + self, + *, + name: Optional[str] = None, + description: Optional[str] = None, + key: Optional[str] = None, + ai_provider_id: Optional[str] = None, + workspace_id: Optional[str] = None, + slug: Optional[str] = None, + organisation_id: Optional[str] = None, + note: Optional[str] = None, + configuration: Optional[Dict[str, Any]] = None, + **kwargs: Any, + ) -> GenericResponse: + body = { + "name": name, + "description": description, + "key": key, + "ai_provider_id": ai_provider_id, + "workspace_id": workspace_id, + "slug": slug, + "organisation_id": organisation_id, + "note": note, + "configuration": configuration, + **kwargs, + } + return self._post( + f"{PortkeyApiPaths.INTEGRATIONS_API}", + body=body, + params=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + def list( + self, + *, + organisation_id: Optional[str] = None, + workspace_id: Optional[str] = None, + current_page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> GenericResponse: + query = { + "organisation_id": organisation_id, + "workspace_id": workspace_id, + "current_page": current_page, + "page_size": page_size, + } + 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.INTEGRATIONS_API}?{query_string}", + params=None, + body=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + def retrieve(self, *, integration_id: Optional[str]) -> Any: + return self._get( + f"{PortkeyApiPaths.INTEGRATIONS_API}/{integration_id}", + params=None, + body=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + def update( + self, + *, + integration_id: Optional[str] = None, + name: Optional[str] = None, + description: Optional[str] = None, + key: Optional[str] = None, + configuration: Optional[Dict[str, Any]] = None, + **kwargs: Any, + ) -> GenericResponse: + body = { + "name": name, + "description": description, + "key": key, + "configuration": configuration, + **kwargs, + } + return self._put( + f"{PortkeyApiPaths.INTEGRATIONS_API}/{integration_id}", + body=body, + params=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + def delete( + self, + *, + integration_id: Optional[str], + ) -> Any: + return self._delete( + f"{PortkeyApiPaths.INTEGRATIONS_API}/{integration_id}", + params=None, + body=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + +class IntegrationsWorkspaces(APIResource): + def __init__(self, client: APIClient) -> None: + super().__init__(client) + + def list( + self, + *, + provider_integration_id: Optional[str] = None, + ) -> GenericResponse: + return self._get( + f"{PortkeyApiPaths.INTEGRATIONS_API}/{provider_integration_id}/workspaces", + params=None, + body=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + def update( + self, + *, + provider_integration_id: Optional[str] = None, + global_workspace_access: Optional[Dict[str, Any]] = None, + workspace_ids: Optional[List[str]] = None, + override_existing_workspaces_access: Optional[bool] = None, + workspaces: Optional[List[Dict[str, Any]]] = None, + **kwargs: Any, + ) -> GenericResponse: + body = { + "global_workspace_access": global_workspace_access, + "workspace_ids": workspace_ids, + "override_existing_workspaces_access": override_existing_workspaces_access, + "workspaces": workspaces, + **kwargs, + } + return self._put( + f"{PortkeyApiPaths.INTEGRATIONS_API}/{provider_integration_id}/workspaces", + body=body, + params=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + +class IntegrationsModels(APIResource): + def __init__(self, client: APIClient) -> None: + super().__init__(client) + + def list( + self, + *, + provider_integration_id: Optional[str] = None, + ) -> GenericResponse: + return self._get( + f"{PortkeyApiPaths.INTEGRATIONS_API}/{provider_integration_id}/models", + params=None, + body=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + def update( + self, + *, + provider_integration_id: Optional[str] = None, + allow_all_models: Optional[bool] = None, + models: Optional[List[Dict[str, Any]]] = None, + **kwargs: Any, + ) -> GenericResponse: + body = { + "allow_all_models": allow_all_models, + "models": models, + **kwargs, + } + return self._put( + f"{PortkeyApiPaths.INTEGRATIONS_API}/{provider_integration_id}/models", + body=body, + params=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + +class AsyncIntegrations(AsyncAPIResource): + def __init__(self, client: AsyncAPIClient) -> None: + super().__init__(client) + self.workspaces = AsyncIntegrationsWorkspaces(client) + self.models = AsyncIntegrationsModels(client) + + async def create( + self, + *, + name: Optional[str] = None, + description: Optional[str] = None, + key: Optional[str] = None, + ai_provider_id: Optional[str] = None, + workspace_id: Optional[str] = None, + slug: Optional[str] = None, + organisation_id: Optional[str] = None, + note: Optional[str] = None, + configuration: Optional[Dict[str, Any]] = None, + **kwargs: Any, + ) -> GenericResponse: + body = { + "name": name, + "description": description, + "key": key, + "ai_provider_id": ai_provider_id, + "workspace_id": workspace_id, + "slug": slug, + "organisation_id": organisation_id, + "note": note, + "configuration": configuration, + **kwargs, + } + return await self._post( + f"{PortkeyApiPaths.INTEGRATIONS_API}", + body=body, + params=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + async def list( + self, + *, + organisation_id: Optional[str] = None, + workspace_id: Optional[str] = None, + current_page: Optional[int] = None, + page_size: Optional[int] = None, + ) -> GenericResponse: + query = { + "organisation_id": organisation_id, + "workspace_id": workspace_id, + "current_page": current_page, + "page_size": page_size, + } + 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.INTEGRATIONS_API}?{query_string}", + params=None, + body=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + async def retrieve(self, *, integration_id: Optional[str]) -> Any: + return await self._get( + f"{PortkeyApiPaths.INTEGRATIONS_API}/{integration_id}", + params=None, + body=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + async def update( + self, + *, + integration_id: Optional[str] = None, + name: Optional[str] = None, + description: Optional[str] = None, + key: Optional[str] = None, + configuration: Optional[Dict[str, Any]] = None, + **kwargs: Any, + ) -> GenericResponse: + body = { + "name": name, + "description": description, + "key": key, + "configuration": configuration, + **kwargs, + } + return await self._put( + f"{PortkeyApiPaths.INTEGRATIONS_API}/{integration_id}", + body=body, + params=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + async def delete( + self, + *, + integration_id: Optional[str], + ) -> Any: + return await self._delete( + f"{PortkeyApiPaths.INTEGRATIONS_API}/{integration_id}", + params=None, + body=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + +class AsyncIntegrationsWorkspaces(AsyncAPIResource): + def __init__(self, client: AsyncAPIClient) -> None: + super().__init__(client) + + async def list( + self, + *, + provider_integration_id: Optional[str] = None, + ) -> GenericResponse: + return await self._get( + f"{PortkeyApiPaths.INTEGRATIONS_API}/{provider_integration_id}/workspaces", + params=None, + body=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + async def update( + self, + *, + provider_integration_id: Optional[str] = None, + global_workspace_access: Optional[Dict[str, Any]] = None, + workspace_ids: Optional[List[str]] = None, + override_existing_workspaces_access: Optional[bool] = None, + workspaces: Optional[List[Dict[str, Any]]] = None, + **kwargs: Any, + ) -> GenericResponse: + body = { + "global_workspace_access": global_workspace_access, + "workspace_ids": workspace_ids, + "override_existing_workspaces_access": override_existing_workspaces_access, + "workspaces": workspaces, + **kwargs, + } + return await self._put( + f"{PortkeyApiPaths.INTEGRATIONS_API}/{provider_integration_id}/workspaces", + body=body, + params=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + +class AsyncIntegrationsModels(AsyncAPIResource): + def __init__(self, client: AsyncAPIClient) -> None: + super().__init__(client) + + async def list( + self, + *, + provider_integration_id: Optional[str] = None, + ) -> GenericResponse: + return await self._get( + f"{PortkeyApiPaths.INTEGRATIONS_API}/{provider_integration_id}/models", + params=None, + body=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) + + async def update( + self, + *, + provider_integration_id: Optional[str] = None, + allow_all_models: Optional[bool] = None, + models: Optional[List[Dict[str, Any]]] = None, + **kwargs: Any, + ) -> GenericResponse: + body = { + "allow_all_models": allow_all_models, + "models": models, + **kwargs, + } + return await self._put( + f"{PortkeyApiPaths.INTEGRATIONS_API}/{provider_integration_id}/models", + body=body, + params=None, + cast_to=GenericResponse, + stream=False, + stream_cls=None, + headers={}, + ) diff --git a/portkey_ai/api_resources/client.py b/portkey_ai/api_resources/client.py index 570401d..d69c825 100644 --- a/portkey_ai/api_resources/client.py +++ b/portkey_ai/api_resources/client.py @@ -35,6 +35,7 @@ class Portkey(APIClient): logs: apis.Logs labels: apis.Labels collections: apis.Collections + integrations: apis.Integrations class beta: assistants: apis.Assistants @@ -175,6 +176,7 @@ def __init__( self.logs = apis.Logs(self) self.labels = apis.Labels(self) self.collections = apis.Collections(self) + self.integrations = apis.Integrations(self) self.beta = self.beta(self) # type: ignore if self.instrumentation: @@ -352,6 +354,7 @@ class AsyncPortkey(AsyncAPIClient): logs: apis.AsyncLogs labels: apis.AsyncLabels collections: apis.AsyncCollections + integrations: apis.AsyncIntegrations class beta: assistants: apis.AsyncAssistants @@ -492,6 +495,7 @@ def __init__( self.logs = apis.AsyncLogs(self) self.labels = apis.AsyncLabels(self) self.collections = apis.AsyncCollections(self) + self.integrations = apis.AsyncIntegrations(self) self.beta = self.beta(self) # type: ignore if self.instrumentation: diff --git a/portkey_ai/api_resources/utils.py b/portkey_ai/api_resources/utils.py index 776c96d..588b3a2 100644 --- a/portkey_ai/api_resources/utils.py +++ b/portkey_ai/api_resources/utils.py @@ -129,6 +129,8 @@ class PortkeyApiPaths(str, Enum, metaclass=MetaEnum): COLLECTIONS_API = "/collections" PROMPTS_API = "/prompts" PROMPTS_PARTIALS_API = "/prompts/partials" + INTEGRATIONS_API = "/integrations" + PROVIDERS_API = "/providers" def __str__(self): return self.value