From 0dbe54759a6ba228d26bd84a2f5e4ed4ee0ab47e Mon Sep 17 00:00:00 2001 From: Junhyuk Lee Date: Wed, 29 Apr 2026 15:20:09 +0000 Subject: [PATCH] Advance OSS contribution for GPT5 Models | Tool choices other than 'auto' are not supported with model Nightly Codex produced a focused contribution for https://github.com/openai/openai-python/issues/2537. Constraint: Automated nightly run; keep changes small and reviewable. Confidence: medium Scope-risk: narrow Tested: See uploaded nightly artifacts and workflow logs. Not-tested: Maintainer CI beyond this workflow. --- NIGHTLY_CODEX_FINAL_ATTEMPT_1.md | 14 ++++++++ tests/lib/responses/test_responses.py | 49 +++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 NIGHTLY_CODEX_FINAL_ATTEMPT_1.md diff --git a/NIGHTLY_CODEX_FINAL_ATTEMPT_1.md b/NIGHTLY_CODEX_FINAL_ATTEMPT_1.md new file mode 100644 index 0000000000..e79a74ce0c --- /dev/null +++ b/NIGHTLY_CODEX_FINAL_ATTEMPT_1.md @@ -0,0 +1,14 @@ +Implemented a small focused contribution for `openai/openai-python#2537`. + +Changed: +- Added `test_streaming_allowed_tools_tool_choice_body` in [tests/lib/responses/test_responses.py](/home/runner/work/oss-nightly-control/oss-nightly-control/target/tests/lib/responses/test_responses.py) +- Added required [NIGHTLY_REPORT.md](/home/runner/work/oss-nightly-control/oss-nightly-control/target/NIGHTLY_REPORT.md) + +Verified: +- `uv run --with pytest --with pytest-asyncio --with respx --with inline-snapshot pytest tests/lib/responses/test_responses.py -q -o addopts=''` passed: `6 passed` +- `uv run --with ruff ruff check tests/lib/responses/test_responses.py` passed +- `uv run --with ruff ruff format --check tests/lib/responses/test_responses.py` passed + +Notes: +- The original 400 appears server/model-policy driven, so I did not add SDK-side validation that could go stale. The test locks the SDK’s request serialization for the reported GPT-5 + streamed `allowed_tools` tool choice shape. +- Existing untracked `.codex-nightly-prompt.md` and `uv.lock` were left untouched. \ No newline at end of file diff --git a/tests/lib/responses/test_responses.py b/tests/lib/responses/test_responses.py index 8e5f16df95..84c52a2a88 100644 --- a/tests/lib/responses/test_responses.py +++ b/tests/lib/responses/test_responses.py @@ -1,7 +1,9 @@ from __future__ import annotations +import json from typing_extensions import TypeVar +import httpx import pytest from respx import MockRouter from inline_snapshot import snapshot @@ -41,6 +43,53 @@ def test_output_text(client: OpenAI, respx_mock: MockRouter) -> None: ) +@pytest.mark.respx(base_url=base_url) +def test_streaming_allowed_tools_tool_choice_body(client: OpenAI, respx_mock: MockRouter) -> None: + respx_mock.post("/responses").mock(return_value=httpx.Response(200, json={})) + + response = client.responses.with_raw_response.create( + model="gpt-5", + input="Use your python tool to do this math: 8*9183*7663", + tools=[ + { + "type": "code_interpreter", + "container": {"type": "auto"}, + } + ], + tool_choice={ + "type": "allowed_tools", + "mode": "auto", + "tools": [ + { + "type": "code_interpreter", + } + ], + }, + stream=True, + ) + + assert json.loads(response.http_request.content) == { + "model": "gpt-5", + "input": "Use your python tool to do this math: 8*9183*7663", + "tools": [ + { + "type": "code_interpreter", + "container": {"type": "auto"}, + } + ], + "tool_choice": { + "type": "allowed_tools", + "mode": "auto", + "tools": [ + { + "type": "code_interpreter", + } + ], + }, + "stream": True, + } + + @pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) def test_stream_method_definition_in_sync(sync: bool, client: OpenAI, async_client: AsyncOpenAI) -> None: checking_client: OpenAI | AsyncOpenAI = client if sync else async_client