Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
### Changelog
#### Unreleased

All notable changes to this project will be documented in this file. Dates are displayed in UTC.
- feat: introducing a "Generate" API for prompt-based content generation with saved prompts

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
<!-- auto-changelog-below -->

#### [v0.1.49](https://github.com/Portkey-AI/portkey-python-sdk/compare/v0.1.48...v0.1.49)

> 16 September 2023

- fix: Fixing the issue with the capturing of env variables [`#13`](https://github.com/Portkey-AI/portkey-python-sdk/pull/13)

#### [v0.1.48](https://github.com/Portkey-AI/portkey-python-sdk/compare/v0.1.45...v0.1.48)

> 14 September 2023

- fix: cache age type fix [`#11`](https://github.com/Portkey-AI/portkey-python-sdk/pull/11)
- docs: updated change log [`#10`](https://github.com/Portkey-AI/portkey-python-sdk/pull/10)

#### [v0.1.45](https://github.com/Portkey-AI/portkey-python-sdk/compare/v0.1.44...v0.1.45)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ All of your LLM provider features work as they would in their own SDKs. For exam
* Set `messages` = `[array]` to set input for models like GPT3.5 & GPT4

Let's see it in action.
```
```python
from portkey import LLMOptions
llm = LLMOptions(
provider="openai",
Expand Down
2 changes: 2 additions & 0 deletions portkey/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ChatCompletionChunk,
TextCompletion,
TextCompletionChunk,
Generations,
)
from portkey.version import VERSION
from portkey.api_resources.global_constants import (
Expand Down Expand Up @@ -50,6 +51,7 @@
"ChatCompletionChunk",
"TextCompletion",
"TextCompletionChunk",
"Generations",
"Config",
"api_key",
"base_url",
Expand Down
3 changes: 2 additions & 1 deletion portkey/api_resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""""""
from .apis import ChatCompletions, Completions
from .apis import ChatCompletions, Completions, Generations
from .utils import (
Modes,
ModesLiteral,
Expand Down Expand Up @@ -41,4 +41,5 @@
"ChatCompletionChunk",
"TextCompletion",
"TextCompletionChunk",
"Generations",
]
47 changes: 30 additions & 17 deletions portkey/api_resources/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ChatCompletion,
TextCompletion,
TextCompletionChunk,
ApiType,
GenericResponse,
)

from .streaming import Stream
Expand Down Expand Up @@ -49,7 +49,7 @@ def create(
max_tokens: Optional[int] = None,
top_k: Optional[int] = None,
top_p: Optional[float] = None,
**kwargs
**kwargs,
) -> Stream[TextCompletionChunk]:
...

Expand All @@ -65,7 +65,7 @@ def create(
max_tokens: Optional[int] = None,
top_k: Optional[int] = None,
top_p: Optional[float] = None,
**kwargs
**kwargs,
) -> TextCompletion:
...

Expand All @@ -81,7 +81,7 @@ def create(
max_tokens: Optional[int] = None,
top_k: Optional[int] = None,
top_p: Optional[float] = None,
**kwargs
**kwargs,
) -> Union[TextCompletion, Stream[TextCompletionChunk]]:
...

Expand All @@ -96,7 +96,7 @@ def create(
max_tokens: Optional[int] = None,
top_k: Optional[int] = None,
top_p: Optional[float] = None,
**kwargs
**kwargs,
) -> Union[TextCompletion, Stream[TextCompletionChunk]]:
if config is None:
config = retrieve_config()
Expand All @@ -107,7 +107,7 @@ def create(
max_tokens=max_tokens,
top_k=top_k,
top_p=top_p,
**kwargs
**kwargs,
)
if config.mode == Modes.SINGLE.value:
return cls(_client)._post(
Expand All @@ -118,7 +118,6 @@ def create(
cast_to=TextCompletion,
stream_cls=Stream[TextCompletionChunk],
stream=stream,
_type=ApiType.COMPLETIONS,
)
if config.mode == Modes.FALLBACK.value:
return cls(_client)._post(
Expand All @@ -129,7 +128,6 @@ def create(
cast_to=TextCompletion,
stream_cls=Stream[TextCompletionChunk],
stream=stream,
_type=ApiType.COMPLETIONS,
)
if config.mode == Modes.AB_TEST.value:
return cls(_client)._post(
Expand All @@ -140,7 +138,6 @@ def create(
cast_to=TextCompletion,
stream_cls=Stream[TextCompletionChunk],
stream=stream,
_type=ApiType.COMPLETIONS,
)
raise NotImplementedError("Mode not implemented.")

Expand All @@ -158,7 +155,7 @@ def create(
max_tokens: Optional[int] = None,
top_k: Optional[int] = None,
top_p: Optional[float] = None,
**kwargs
**kwargs,
) -> Stream[ChatCompletionChunk]:
...

Expand All @@ -174,7 +171,7 @@ def create(
max_tokens: Optional[int] = None,
top_k: Optional[int] = None,
top_p: Optional[float] = None,
**kwargs
**kwargs,
) -> ChatCompletion:
...

Expand All @@ -190,7 +187,7 @@ def create(
max_tokens: Optional[int] = None,
top_k: Optional[int] = None,
top_p: Optional[float] = None,
**kwargs
**kwargs,
) -> Union[ChatCompletion, Stream[ChatCompletionChunk]]:
...

Expand All @@ -205,7 +202,7 @@ def create(
max_tokens: Optional[int] = None,
top_k: Optional[int] = None,
top_p: Optional[float] = None,
**kwargs
**kwargs,
) -> Union[ChatCompletion, Stream[ChatCompletionChunk]]:
if config is None:
config = retrieve_config()
Expand All @@ -216,7 +213,7 @@ def create(
max_tokens=max_tokens,
top_k=top_k,
top_p=top_p,
**kwargs
**kwargs,
)
if config.mode == Modes.SINGLE.value:
return cls(_client)._post(
Expand All @@ -227,7 +224,6 @@ def create(
cast_to=ChatCompletion,
stream_cls=Stream[ChatCompletionChunk],
stream=stream,
_type=ApiType.CHAT_COMPLETION,
)
if config.mode == Modes.FALLBACK.value:
return cls(_client)._post(
Expand All @@ -238,7 +234,6 @@ def create(
cast_to=ChatCompletion,
stream_cls=Stream[ChatCompletionChunk],
stream=stream,
_type=ApiType.CHAT_COMPLETION,
)
if config.mode == Modes.AB_TEST.value:
return cls(_client)._post(
Expand All @@ -249,6 +244,24 @@ def create(
cast_to=ChatCompletion,
stream_cls=Stream[ChatCompletionChunk],
stream=stream,
_type=ApiType.CHAT_COMPLETION,
)
raise NotImplementedError("Mode not implemented.")


class Generations(APIResource):
@classmethod
def create(
cls, *, prompt_id: str, config: Optional[Config] = None, **kwargs
) -> Union[GenericResponse, Stream[GenericResponse]]:
if config is None:
config = retrieve_config()
_client = APIClient(api_key=config.api_key, base_url=config.base_url)
return cls(_client)._post(
f"/v1/prompts/{prompt_id}/generate",
body=config.llms,
mode=None,
params=None,
cast_to=GenericResponse,
stream_cls=Stream[GenericResponse],
stream=False,
)
Loading