Skip to content

Commit

Permalink
Merge pull request #96 from Portkey-AI/feat/render
Browse files Browse the repository at this point in the history
Feat/render
  • Loading branch information
VisargD authored Mar 23, 2024
2 parents 72f3ea8 + 7577329 commit b7f70df
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions portkey_ai/api_resources/apis/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,38 @@ def __init__(self, client: APIClient) -> None:
super().__init__(client)
self.completions = Completions(client)

def render(
self,
*,
prompt_id: str,
variables: Optional[Mapping[str, Any]] = None,
stream: bool = False,
temperature: Optional[float] = None,
max_tokens: Optional[int] = None,
top_k: Optional[int] = None,
top_p: Optional[float] = None,
**kwargs,
) -> GenericResponse:
"""Prompt render Method"""
body = {
"variables": variables,
"temperature": temperature,
"max_tokens": max_tokens,
"top_k": top_k,
"top_p": top_p,
"stream": stream,
**kwargs,
}
return self._post(
f"/prompts/{prompt_id}/render",
body=body,
params=None,
cast_to=GenericResponse,
stream_cls=Stream[GenericResponse],
stream=False,
headers={},
)


class AsyncPrompts(AsyncAPIResource):
completions: AsyncCompletions
Expand All @@ -92,6 +124,36 @@ def __init__(self, client: AsyncAPIClient) -> None:
super().__init__(client)
self.completions = AsyncCompletions(client)

async def render(
self,
*,
prompt_id: str,
variables: Optional[Mapping[str, Any]] = None,
temperature: Optional[float] = None,
max_tokens: Optional[int] = None,
top_k: Optional[int] = None,
top_p: Optional[float] = None,
**kwargs,
) -> GenericResponse:
"""Prompt render Method"""
body = {
"variables": variables,
"temperature": temperature,
"max_tokens": max_tokens,
"top_k": top_k,
"top_p": top_p,
**kwargs,
}
return await self._post(
f"/prompts/{prompt_id}/render",
body=body,
params=None,
cast_to=GenericResponse,
stream=False,
stream_cls=AsyncStream[GenericResponse],
headers={},
)


class Completions(APIResource):
def __init__(self, client: APIClient) -> None:
Expand Down

0 comments on commit b7f70df

Please sign in to comment.