Repository navigation
feat(api): share Decisions cache breakpoint parameter type #4092
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
Merged
+165
−45
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| schema_version: 1 | ||
| generation_id: faf10787-3bdc-4568-b380-0861d1d6e36a | ||
| openapi_spec_hash: e767920c3fa8361ad29a90c8ea8397f2 | ||
| openapi_transformed_spec_hash: 0ed231f6f1bee5e6180d6d4e4691cf92 | ||
| config_hash: 83d6d59dd355a0913b94b00a8e37347f | ||
| codegen_sha: 1723773fd709b9e05fe6b2a0dba6bd89a0e7b644 | ||
| codegen_hash: 209068bfadf82bbebdd982054c230b05718b15083751c01b498c1eb01bd4de3b | ||
| public_codegen_sha: e91edab5b26cd158367b0faa4b3a13d323988180 | ||
| generation_id: 87b7588c-bf2a-41c6-9369-25b7fac9406c | ||
| openapi_spec_hash: 5dc81283fba93dcfeaeca3da5226d157 | ||
| openapi_transformed_spec_hash: 42319a087893dfea0fdd818494eb2a8d | ||
| config_hash: c1867d38e1fb20037598907749312f81 | ||
| codegen_sha: 0312112d44322208df3d1587c5b6eac1867be196 | ||
| codegen_hash: c6efe506a6d3c692825695e888a088db61e9f7c1115801a7138ba4b3ec8b1d00 | ||
| public_codegen_sha: 54359420e01e63cc0b61838459b07fcf8cc3a7bd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/openai/types/decision_prompt_cache_breakpoint_param.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing_extensions import Literal, Required, TypedDict | ||
|
|
||
| __all__ = ["DecisionPromptCacheBreakpointParam"] | ||
|
|
||
|
|
||
| class DecisionPromptCacheBreakpointParam(TypedDict, total=False): | ||
| """Marks the exact end of a reusable prompt prefix. | ||
| The breakpoint inherits its TTL from the request's `prompt_cache_options.ttl`; the boundary is not rounded to a token block. | ||
| """ | ||
|
|
||
| mode: Required[Literal["explicit"]] | ||
| """The breakpoint mode. Always `explicit`.""" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from typing import TYPE_CHECKING, Any, Optional, get_type_hints | ||
| from typing_extensions import Literal, Required | ||
|
|
||
| import httpx2 | ||
| import pytest | ||
|
|
||
| from openai import OpenAI, AsyncOpenAI | ||
| from openai.types.decision_input_text_param import PromptCacheBreakpoint as TextBreakpoint, DecisionInputTextParam | ||
| from openai.types.decision_input_image_param import PromptCacheBreakpoint as ImageBreakpoint, DecisionInputImageParam | ||
| from openai.types.decision_prompt_cache_breakpoint_param import DecisionPromptCacheBreakpointParam | ||
|
|
||
| if TYPE_CHECKING: | ||
| old_text: TextBreakpoint = {"mode": "explicit"} | ||
| old_image: ImageBreakpoint = {"mode": "explicit"} | ||
| shared_from_text: DecisionPromptCacheBreakpointParam = old_text | ||
| shared_from_image: DecisionPromptCacheBreakpointParam = old_image | ||
| text: DecisionInputTextParam = { | ||
| "type": "input_text", | ||
| "text": "synthetic", | ||
| "prompt_cache_breakpoint": shared_from_image, | ||
| } | ||
| image: DecisionInputImageParam = { | ||
| "type": "input_image", | ||
| "image_url": "https://example.test/image.png", | ||
| "prompt_cache_breakpoint": shared_from_text, | ||
| } | ||
|
|
||
|
|
||
| def test_legacy_breakpoint_exports() -> None: | ||
| for cls in (TextBreakpoint, ImageBreakpoint, DecisionPromptCacheBreakpointParam): | ||
| assert cls(mode="explicit") == {"mode": "explicit"} | ||
| assert get_type_hints(cls, include_extras=True)["mode"] == Required[Literal["explicit"]] | ||
| assert TextBreakpoint.__module__ == "openai.types.decision_input_text_param" | ||
| assert ImageBreakpoint.__module__ == "openai.types.decision_input_image_param" | ||
|
|
||
|
|
||
| def test_shared_breakpoint_annotations() -> None: | ||
| for cls in (DecisionInputTextParam, DecisionInputImageParam): | ||
| assert get_type_hints(cls)["prompt_cache_breakpoint"] == Optional[DecisionPromptCacheBreakpointParam] | ||
|
|
||
|
|
||
| def request_body(mode: str) -> dict[str, Any]: | ||
| content: list[dict[str, Any]] = [ | ||
| {"type": "input_text", "text": "synthetic"}, | ||
| {"type": "input_image", "image_url": "https://example.test/image.png"}, | ||
| ] | ||
| body: dict[str, Any] = { | ||
| "model": "synthetic-model", | ||
| "input": [{"role": "user", "content": content}], | ||
| "questions": [{"instructions": "Synthetic question", "type": "predicate"}], | ||
| } | ||
| if mode != "omitted": | ||
| body["prompt_cache_key"] = None if mode == "nulls" else "synthetic-key" | ||
| body["prompt_cache_options"] = None if mode == "nulls" else {"mode": mode, "ttl": "30m"} | ||
| for part in content: | ||
| part["prompt_cache_breakpoint"] = None if mode == "nulls" else {"mode": "explicit"} | ||
| return body | ||
|
|
||
|
|
||
| def capture_request(request: httpx2.Request, captured: list[dict[str, Any]]) -> httpx2.Response: | ||
| assert request.method == "POST" | ||
| assert str(request.url) == "https://example.test/decisions" | ||
| captured.append(json.loads(request.content)) | ||
| return httpx2.Response( | ||
| 200, json={"id": "decision_synthetic", "answers": [], "model": "synthetic-model", "usage": {}} | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("mode", ["explicit", "implicit", "nulls", "omitted"]) | ||
| def test_sync_request(mode: str) -> None: | ||
| captured: list[dict[str, Any]] = [] | ||
| body = request_body(mode) | ||
| with OpenAI( | ||
| api_key="fake-test-key", | ||
| base_url="https://example.test", | ||
| max_retries=0, | ||
| http_client=httpx2.Client( | ||
| transport=httpx2.MockTransport(lambda request: capture_request(request, captured)), trust_env=False | ||
| ), | ||
| ) as client: | ||
| client.decisions.create(**body) | ||
| assert captured == [body] | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.parametrize("mode", ["explicit", "implicit", "nulls", "omitted"]) | ||
| async def test_async_request(mode: str) -> None: | ||
| captured: list[dict[str, Any]] = [] | ||
| body = request_body(mode) | ||
| async with AsyncOpenAI( | ||
| api_key="fake-test-key", | ||
| base_url="https://example.test", | ||
| max_retries=0, | ||
| http_client=httpx2.AsyncClient( | ||
| transport=httpx2.MockTransport(lambda request: capture_request(request, captured)), trust_env=False | ||
| ), | ||
| ) as client: | ||
| await client.decisions.create(**body) | ||
| assert captured == [body] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.