|
| 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) |
0 commit comments