Skip to content
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
4 changes: 4 additions & 0 deletions portkey_ai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
AsyncContainersFiles,
Content,
AsyncContent,
PostMethod,
AsyncPostMethod,
)

from portkey_ai.version import VERSION
Expand Down Expand Up @@ -265,4 +267,6 @@
"AsyncContainersFiles",
"Content",
"AsyncContent",
"PostMethod",
"AsyncPostMethod",
]
4 changes: 4 additions & 0 deletions portkey_ai/api_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
AsyncContainersFiles,
Content,
AsyncContent,
PostMethod,
AsyncPostMethod,
)
from .utils import (
Modes,
Expand Down Expand Up @@ -257,4 +259,6 @@
"AsyncContainersFiles",
"Content",
"AsyncContent",
"PostMethod",
"AsyncPostMethod",
]
4 changes: 3 additions & 1 deletion portkey_ai/api_resources/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .generation import Generations, AsyncGenerations, Prompts, AsyncPrompts
from .feedback import Feedback, AsyncFeedback
from .create_headers import createHeaders
from .post import Post, AsyncPost
from .post import Post, AsyncPost, PostMethod, AsyncPostMethod
from .getMethod import GetMethod, AsyncGetMethod
from .deleteMethod import DeleteMethod, AsyncDeleteMethod
from .putMethod import PutMethod, AsyncPutMethod
Expand Down Expand Up @@ -157,6 +157,8 @@
"createHeaders",
"Post",
"AsyncPost",
"PostMethod",
"AsyncPostMethod",
"GetMethod",
"AsyncGetMethod",
"DeleteMethod",
Expand Down
132 changes: 131 additions & 1 deletion portkey_ai/api_resources/apis/post.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union, overload, Literal
from typing import Any, Dict, Optional, Union, overload, Literal

from portkey_ai.api_resources.base_client import APIClient, AsyncAPIClient

Expand Down Expand Up @@ -115,3 +115,133 @@ async def create(
stream=stream,
headers=headers,
)


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

@overload
def create(
self,
path: Optional[str] = None,
body: Optional[Dict[str, Any]] = {},
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
stream: Literal[True] = True,
**kwargs,
) -> Stream[GenericResponse]:
...

@overload
def create(
self,
path: Optional[str] = None,
body: Optional[Dict[str, Any]] = {},
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
stream: Literal[False] = False,
**kwargs,
) -> GenericResponse:
...

@overload
def create(
self,
path: Optional[str] = None,
body: Optional[Dict[str, Any]] = {},
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
stream: bool = False,
**kwargs,
) -> Union[GenericResponse, Stream[GenericResponse]]:
...

def create(
self,
path: Optional[str] = None,
body: Optional[Dict[str, Any]] = {},
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
stream: bool = False,
**kwargs,
) -> Union[GenericResponse, Stream[GenericResponse]]:
files = kwargs.pop("files", None)
headers = headers or kwargs.pop("headers", {})
body = body or kwargs

return self._post(
path=path,
body=body,
files=files,
params={},
headers=headers,
cast_to=cast_to,
stream=stream,
stream_cls=Stream[GenericResponse],
)


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

@overload
async def create(
self,
path: Optional[str] = None,
body: Optional[Dict[str, Any]] = {},
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
stream: Literal[True] = True,
**kwargs,
) -> Stream[GenericResponse]:
...

@overload
async def create(
self,
path: Optional[str] = None,
body: Optional[Dict[str, Any]] = {},
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
stream: Literal[False] = False,
**kwargs,
) -> GenericResponse:
...

@overload
async def create(
self,
path: Optional[str] = None,
body: Optional[Dict[str, Any]] = {},
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
stream: bool = False,
**kwargs,
) -> Union[GenericResponse, Stream[GenericResponse]]:
...

async def create(
self,
path: Optional[str] = None,
body: Optional[Dict[str, Any]] = {},
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
stream: bool = False,
**kwargs,
) -> Union[GenericResponse, Stream[GenericResponse]]:
files = kwargs.pop("files", None)
headers = headers or kwargs.pop("headers", {})
body = body or kwargs

return await self._post(
path=path,
body=body,
files=files,
params={},
headers=headers,
cast_to=cast_to,
stream=stream,
stream_cls=Stream[GenericResponse],
)
42 changes: 42 additions & 0 deletions portkey_ai/api_resources/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,27 @@ def copy(
def post(self, url: str, **kwargs):
return apis.Post(self).create(url=url, **kwargs)

def postMethod(
self,
*,
path: Optional[str] = None,
url: Optional[str] = None,
body: Optional[Dict[str, Any]] = {},
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
stream: bool = False,
**kwargs,
):
path = path or url
return apis.PostMethod(self).create(
path=path,
body=body,
headers=headers,
cast_to=cast_to,
stream=stream,
**kwargs,
)

def get(
self,
*,
Expand Down Expand Up @@ -608,6 +629,27 @@ def copy(
async def post(self, url: str, **kwargs):
return await apis.AsyncPost(self).create(url=url, **kwargs)

async def postMethod(
self,
*,
path: Optional[str] = None,
url: Optional[str] = None,
body: Optional[Dict[str, Any]] = {},
headers: Optional[Dict[str, str]] = {},
cast_to: Optional[Any] = None,
stream: bool = False,
**kwargs,
):
path = path or url
return await apis.AsyncPostMethod(self).create(
path=path,
body=body,
headers=headers,
cast_to=cast_to,
stream=stream,
**kwargs,
)

async def get(
self,
*,
Expand Down