Skip to content

GET, DELETE and PUT Support #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions portkey_ai/api_resources/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from .feedback import Feedback, AsyncFeedback
from .create_headers import createHeaders
from .post import Post, AsyncPost
from .getMethod import GetMethod, AsyncGetMethod
from .deleteMethod import DeleteMethod, AsyncDeleteMethod
from .putMethod import PutMethod, AsyncPutMethod
from .embeddings import Embeddings, AsyncEmbeddings
from .images import Images, AsyncImages
from .assistants import Assistants, AsyncAssistants
Expand Down Expand Up @@ -145,6 +148,12 @@
"createHeaders",
"Post",
"AsyncPost",
"GetMethod",
"AsyncGetMethod",
"DeleteMethod",
"AsyncDeleteMethod",
"PutMethod",
"AsyncPutMethod",
"Embeddings",
"AsyncEmbeddings",
"Images",
Expand Down
45 changes: 45 additions & 0 deletions portkey_ai/api_resources/apis/deleteMethod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from typing import Any, Dict, Optional
from portkey_ai.api_resources.apis.api_resource import APIResource, AsyncAPIResource
from portkey_ai.api_resources.base_client import APIClient, AsyncAPIClient


class DeleteMethod(APIResource):
def __init__(self, client: APIClient) -> None:
super().__init__(client)

def create(
self,
path: str,
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
):
return self._delete(
path=path,
body={},
params={},
headers=headers,
cast_to=cast_to,
stream=False,
stream_cls=None,
)


class AsyncDeleteMethod(AsyncAPIResource):
def __init__(self, client: AsyncAPIClient) -> None:
super().__init__(client)

async def create(
self,
path: str,
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
):
return await self._delete(
path=path,
body={},
params={},
headers=headers,
cast_to=cast_to,
stream=False,
stream_cls=None,
)
45 changes: 45 additions & 0 deletions portkey_ai/api_resources/apis/getMethod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from typing import Any, Dict, Optional
from portkey_ai.api_resources.apis.api_resource import APIResource, AsyncAPIResource
from portkey_ai.api_resources.base_client import APIClient, AsyncAPIClient


class GetMethod(APIResource):
def __init__(self, client: APIClient) -> None:
super().__init__(client)

def create(
self,
path: str,
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
):
return self._get(
path=path,
body={},
params={},
headers=headers,
cast_to=cast_to,
stream=False,
stream_cls=None,
)


class AsyncGetMethod(AsyncAPIResource):
def __init__(self, client: AsyncAPIClient) -> None:
super().__init__(client)

async def create(
self,
path: str,
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
):
return await self._get(
path=path,
body={},
params={},
headers=headers,
cast_to=cast_to,
stream=False,
stream_cls=None,
)
47 changes: 47 additions & 0 deletions portkey_ai/api_resources/apis/putMethod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from typing import Any, Dict, Optional
from portkey_ai.api_resources.apis.api_resource import APIResource, AsyncAPIResource
from portkey_ai.api_resources.base_client import APIClient, AsyncAPIClient


class PutMethod(APIResource):
def __init__(self, client: APIClient) -> None:
super().__init__(client)

def create(
self,
path: str,
body: Optional[Dict[str, Any]] = {},
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
):
return self._put(
path=path,
body=body,
params={},
headers=headers,
cast_to=cast_to,
stream=False,
stream_cls=None,
)


class AsyncPutMethod(AsyncAPIResource):
def __init__(self, client: AsyncAPIClient) -> None:
super().__init__(client)

async def create(
self,
path: str,
body: Optional[Dict[str, Any]] = {},
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
):
return await self._put(
path=path,
body=body,
params={},
headers=headers,
cast_to=cast_to,
stream=False,
stream_cls=None,
)
68 changes: 67 additions & 1 deletion portkey_ai/api_resources/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from typing import List, Mapping, Optional, Union
from typing import Any, Dict, List, Mapping, Optional, Union
import httpx
from portkey_ai.api_resources import apis
from portkey_ai.api_resources.base_client import APIClient, AsyncAPIClient
Expand Down Expand Up @@ -289,6 +289,38 @@ def copy(
def post(self, url: str, **kwargs):
return apis.Post(self).create(url=url, **kwargs)

def get(
self,
*,
path: str,
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
):
return apis.GetMethod(self).create(path=path, headers=headers, cast_to=cast_to)

def delete(
self,
*,
path: str,
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
):
return apis.DeleteMethod(self).create(
path=path, headers=headers, cast_to=cast_to
)

def put(
self,
*,
path: str,
body: Optional[Dict[str, Any]] = {},
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
):
return apis.PutMethod(self).create(
path=path, body=body, headers=headers, cast_to=cast_to
)

with_options = copy


Expand Down Expand Up @@ -572,4 +604,38 @@ def copy(
async def post(self, url: str, **kwargs):
return await apis.AsyncPost(self).create(url=url, **kwargs)

async def get(
self,
*,
path: str,
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
):
return await apis.AsyncGetMethod(self).create(
path=path, headers=headers, cast_to=cast_to
)

async def delete(
self,
*,
path: str,
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
):
return await apis.AsyncDeleteMethod(self).create(
path=path, headers=headers, cast_to=cast_to
)

async def put(
self,
*,
path: str,
body: Optional[Dict[str, Any]] = {},
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
):
return await apis.AsyncPutMethod(self).create(
path=path, body=body, headers=headers, cast_to=cast_to
)

with_options = copy