Skip to content
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

feat(endpoints): upgrade to assistants v2 #12

Merged
merged 16 commits into from
Apr 24, 2024
Merged
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
40 changes: 40 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Tox

on:
pull_request:
paths:
- "src/**"
- pyproject.toml

jobs:
run:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- name: Checkout branch
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Setup Poetry
uses: abatilo/actions-poetry@v2.0.0
with:
poetry-version: 1.8.2

- name: Install dependencies
shell: bash
run: |
poetry config virtualenvs.in-project true && \
poetry install --with dev

- name: Tox run
shell: bash
run: poetry run tox run
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.mypy_cache/
.pytest_cache/
.tox/
.venv/
.vscode/
__pycache__/
Expand Down
43 changes: 43 additions & 0 deletions docs/endpoints/assistants/messages.md
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
# Messages

!!! warning

There is currently no support for attaching files. Subscribe to [#5: feat: add support for attached files for all assistants APIs](https://github.com/mharrisb1/openai-responses-python/issues/5) to be notified when this is added.

!!! note

Only Assistants V2 is supported

!!! tip

See [examples](https://github.com/mharrisb1/openai-responses-python/blob/main/examples/test_threads_api.py) for more

## Decorator Arguments

- `latency` - synthetic latency in seconds to introduce to the call(s). Defaults to `0.0`.
- `failures` - number of failures to simulate. Defaults to `0`.
- `state_store` - Optional [state store](../../user_guide/state.md) override for custom and shared states.
- `validate_thread_exists` - Optional flag for asserting that thread exists. Defaults to `False`.

## Create message

!!! info

Docs are incomplete but feature is supported

## List messages

!!! info

Docs are incomplete but feature is supported

## Retrieve message

!!! info

Docs are incomplete but feature is supported

## Modify message

!!! info

Docs are incomplete but feature is supported
29 changes: 29 additions & 0 deletions docs/endpoints/assistants/run_steps.md
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
# Run Steps

!!! note

Only Assistants V2 is supported

!!! tip

See [examples](https://github.com/mharrisb1/openai-responses-python/blob/main/examples/test_threads_api.py) for more

## Decorator Arguments

- `latency` - synthetic latency in seconds to introduce to the call(s). Defaults to `0.0`.
- `failures` - number of failures to simulate. Defaults to `0`.
- `state_store` - Optional [state store](../../user_guide/state.md) override for custom and shared states.
- `steps` - Optional steps list. This is needed since there is no create steps route. Defaults to `[]`.
- `validate_thread_exists` - Optional flag for asserting that thread exists. Defaults to `False`.
- `validate_run_exists` - Optional flag for asserting that run exists. Defaults to `False`.

## List run steps

!!! info

Docs are incomplete but feature is supported

## Retrieve run step

!!! info

Docs are incomplete but feature is supported
57 changes: 57 additions & 0 deletions docs/endpoints/assistants/runs.md
Original file line number Diff line number Diff line change
@@ -1 +1,58 @@
# Runs

!!! note

Only Assistants V2 is supported

!!! tip

See [examples](https://github.com/mharrisb1/openai-responses-python/blob/main/examples/test_threads_api.py) for more

## Decorator Arguments

- `latency` - synthetic latency in seconds to introduce to the call(s). Defaults to `0.0`.
- `failures` - number of failures to simulate. Defaults to `0`.
- `state_store` - Optional [state store](../../user_guide/state.md) override for custom and shared states.
- `sequence` - Optional state sequences for create and/or retrieve. Will use sequence `n` for call `n - failure`. Defaults to `{}`
- `validate_thread_exists` - Optional flag for asserting that thread exists. Defaults to `False`.
- `validate_assistant_exists` - Optional flag for asserting that assistant exists. Defaults to `False`.

## Create run

!!! warning

Messages created with `additional_messages` request params are currently ignored. Subscribe to [#10: fix: create run ignores `additional_messages`](https://github.com/mharrisb1/openai-responses-python/issues/10) to be notified when this is fixed

!!! info

Docs are incomplete but feature is supported

## Create thread and run

!!! warning

Not implemented. Subscribe to [#11: feat: support create thread and run route](https://github.com/mharrisb1/openai-responses-python/issues/11) to be notified when support is added.

## Retrieve run

!!! info

Docs are incomplete but feature is supported

## Modify run

!!! info

Docs are incomplete but feature is supported

## Submit tool outputs to run

!!! info

Docs are incomplete but feature is supported

## Cancel run

!!! info

Docs are incomplete but feature is supported
24 changes: 24 additions & 0 deletions docs/endpoints/assistants/threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,27 @@
- `latency` - synthetic latency in seconds to introduce to the call(s). Defaults to `0.0`.
- `failures` - number of failures to simulate. Defaults to `0`.
- `state_store` - Optional [state store](../../user_guide/state.md) override for custom and shared states.

## Create thread

!!! info

Docs are incomplete but feature is supported

## Retrive thread

!!! info

Docs are incomplete but feature is supported

## Modify thread

!!! info

Docs are incomplete but feature is supported

## Delete thread

!!! info

Docs are incomplete but feature is supported
2 changes: 1 addition & 1 deletion docs/endpoints/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Table is assembled according to APIs listed in the [OpenAI API Reference](https:
| Moderations | :material-close: | - | Stateless |
| [Assistants](assistants/assistants.md) | :material-check:[^3] | - | Stateful |
| [Threads](assistants/threads.md) | :material-check-all: | - | Stateful |
| [Messages](assistants/messages.md) | :material-check:[^3] | :material-close: | Stateful |
| [Messages](assistants/messages.md) | :material-check:[^3] | - | Stateful |
| [Runs](assistants/runs.md) | :material-check:[^4][^5] | :material-close: | Stateful |
| [Run Steps](assistants/run_steps.md) | :material-check:[^6] | - | Stateful |
| Vector Stores | :material-close: | - | Stateful |
Expand Down
9 changes: 1 addition & 8 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pytest plugin for automatically mocking OpenAI requests. See the [user guide](us
!!! note

This project does not try to generate fake responses from the models. Any part of a response that would be generated by a model will need to
be defined by the user or will be left as the fallback value (i.e. empty string for `str` type fields).
be defined by the user or will fallback to a default value.

## Installation

Expand All @@ -22,10 +22,3 @@ Available on [PyPi](https://pypi.org/project/openai-responses/)
```shell
poetry add --group dev openai-responses
```

## Why use this?

For building production-ready AI features, you need to add tests to your code. A lot of work and attention is going into evals but the performance of the AI model is only part of the testing story.
Your AI features live with all of the other code in your app and you need to be able to test those interactions.

To avoid actually using the OpenAI endpoints in your tests - which cost money and are probabilistic - you can mock those calls so that everything works the way it will in production but with predetermined responses.
2 changes: 1 addition & 1 deletion docs/user_guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ View available [endpoints](../endpoints/index.md).
!!! note

This project does not try to generate fake responses from the models. Any part of a response that would be generated by a model will need to
be defined by the user or will be left as the fallback value (i.e. empty string for `str` type fields).
be defined by the user or will fallback to a default value.

## Example

Expand Down
1 change: 0 additions & 1 deletion examples/test_threads_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def test_create_thread_with_messages(threads_mock: ThreadsMock):
{
"role": "user",
"content": "Hello, what is AI?",
"file_ids": ["file-abc123"],
},
{
"role": "user",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pytest = "^8.1.1"
pytest-asyncio = "^0.23.6"
types-decorator = "^5.1.8.20240310"
mkdocs-material = "^9.5.18"
tox = "^4.14.2"

[build-system]
requires = ["poetry-core"]
Expand Down
20 changes: 12 additions & 8 deletions src/openai_responses/endpoints/_partial_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
__all__ = ["PartialRun", "PartialRunStep"]


class PartialIncompleteDetails(TypedDict):
reason: Optional[Literal["max_completion_tokens", "max_prompt_tokens"]]


class PartialFunctionNoOutput(TypedDict):
name: str
arguments: str
Expand All @@ -34,18 +38,18 @@ class PartialLastError(TypedDict, total=False):


class PartialRun(TypedDict, total=False):
status: RunStatus
required_action: PartialRequiredAction
last_error: PartialLastError
expires_at: int
started_at: int
cancelled_at: int
failed_at: int
completed_at: int
model: str
expires_at: int
failed_at: int
incomplete_details: PartialIncompleteDetails
instructions: str
last_error: PartialLastError
model: str
required_action: PartialRequiredAction
started_at: int
status: RunStatus
tools: List[AssistantToolParam]
file_ids: List[str]


class PartialCodeInterpreterOutputLogs(TypedDict):
Expand Down
Loading
Loading