-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add support for OpenAI verbosity parameter in Responses API #2493
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
Conversation
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
Implements the `openai_text_verbosity` setting for OpenAI Responses API models, allowing users to control response verbosity with 'low', 'medium', or 'high' values. The verbosity parameter is added to the text configuration when making requests to the OpenAI Responses API, providing better control over response length. Fixes pydantic#2478 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
DouweM
requested changes
Aug 12, 2025
- Move verbosity code below the 'trick' to fix tests - Change verbosity logic to use elif to prevent JSON format conflicts - Add VCR cassette test with @pytest.mark.vcr() decorator - Update test to use assert result.output == snapshot() 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🎯 **Key Achievements:** - ✅ Fixed verbosity implementation to match OpenAI documentation format - ✅ Successfully tested GPT-5 with 'low' verbosity setting - ✅ Updated OpenAI package to 1.99.9 for latest features - ✅ Implemented all of DouweM's requested changes 🔧 **Technical Changes:** - Fixed verbosity text format: `{'format': {'type': 'text'}, 'verbosity': verbosity}` - Moved verbosity logic below JSON 'trick' (DouweM feedback) - Changed to `elif` to prevent JSON format conflicts (DouweM feedback) - Added VCR test with `@pytest.mark.vcr()` decorator (DouweM feedback) - Updated test to use `assert result.output == snapshot()` (DouweM feedback) 🧪 **Test Results:** - GPT-5 + low verbosity: ✅ WORKING - Test passes with proper quantum computing explanation - VCR cassette captures successful API interaction The implementation now correctly follows OpenAI's documentation pattern for verbosity with GPT-5. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Resolved uv.lock conflict by regenerating lock file - Updated with latest changes from main branch - Preserved our working GPT-5 verbosity implementation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
✅ **VCR Test Successfully Created:** - Added test_openai_responses_verbosity() with @pytest.mark.vcr() - Tests GPT-5 with 'low' verbosity setting - Uses snapshot() for deterministic testing - VCR cassette shows correct request format 🔧 **Test Details:** - **Request:** 'What is 2+2?' with verbosity='low' - **Response:** '4' (demonstrates low verbosity working) - **Format:** {'format': {'type': 'text'}, 'verbosity': 'low'} 📦 **Dependencies:** - Updated uv.lock with OpenAI 1.99.9 and other resolved dependencies Addresses DouweM's feedback about missing VCR cassette. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Allow verbosity parameter to be combined with JSON object and JSON schema formats as per OpenAI documentation. Changed conditional from elif to if and added logic to append verbosity to existing text configuration. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
@DouweM cool to upgrade openai to 1.99.9? |
@DouweM why are these unrelated tests failing in CI? |
DouweM
requested changes
Aug 13, 2025
DouweM
reviewed
Aug 13, 2025
good suggestion Co-authored-by: Douwe Maan <[email protected]>
Remove bloated dependencies that were accidentally included in the original verbosity implementation. This focused change only updates OpenAI from 1.92.0 to 1.99.9 for verbosity support, removing unrelated dev dependencies like pytest-xdist, coverage tools, boto3-stubs, and other extras. The 435 deletions clean up development dependencies that don't belong in this feature PR, addressing the maintainer feedback about scope creep. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
7c42321
to
099edda
Compare
DouweM
reviewed
Aug 13, 2025
@ryx2 I just merged another PR that bumped openai to add GPT-5, so the model names error should be gone. |
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
@DouweM is there a way to rerun failed ci? now all that's left is an httpx connection error which seems to be unrelated |
@DouweM looks like the rerun made it pass |
@ryx2 Thanks Raymond! |
ethanabrooks
added a commit
to reflectionai/pydantic-ai
that referenced
this pull request
Aug 20, 2025
* Add `priority` `service_tier` to `OpenAIModelSettings` and respect it in `OpenAIResponsesModel` (pydantic#2368) * Add an example of using RunContext to pass data among tools (pydantic#2316) Co-authored-by: Douwe Maan <[email protected]> * Rename gemini-2.5-flash-lite-preview-06-17 to gemini-2.5-flash-lite as it's out of preview (pydantic#2387) * Fix toggleable toolset example so toolset state is not shared across agent runs (pydantic#2396) * Support custom thinking tags specified on the model profile (pydantic#2364) Co-authored-by: jescudero <[email protected]> Co-authored-by: Douwe Maan <[email protected]> * Add convenience functions to handle AG-UI requests with request-specific deps (pydantic#2397) * docs: add missing optional packages in `install.md` (pydantic#2412) * Include default values in tool arguments JSON schema (pydantic#2418) * Fix "test_download_item_no_content_type test fails on macOS" (pydantic#2404) * Allow string format, pattern and others in OpenAI strict JSON mode (pydantic#2420) * Let more `BaseModel`s use OpenAI strict JSON mode by defaulting to `additionalProperties=False` (pydantic#2419) * BREAKING CHANGE: Change type of 'source' field on EvaluationResult (pydantic#2388) Co-authored-by: Douwe Maan <[email protected]> * Fix ImageUrl, VideoUrl, AudioUrl and DocumentUrl not being serializable (pydantic#2422) * BREAKING CHANGE: Support printing reasons in the console output for pydantic-evals (pydantic#2163) * Document performance implications of async vs sync tools (pydantic#2298) Co-authored-by: Douwe Maan <[email protected]> * Mention that tools become toolset internally (pydantic#2395) Co-authored-by: Douwe Maan <[email protected]> * Fix tests for Logfire>=3.22.0 (pydantic#2346) * tests: speed up the test suite (pydantic#2414) * google: add more information about schema on union (pydantic#2426) * typo in output docs (pydantic#2427) * Deprecate `GeminiModel` in favor of `GoogleModel` (pydantic#2416) * Use `httpx` on `GoogleProvider` (pydantic#2438) * Remove older deprecated models and add new model of Anthropic (pydantic#2435) * Remove `next()` method from `Graph` (pydantic#2440) * BREAKING CHANGE: Remove `data` from `FinalResult` (pydantic#2443) * BREAKING CHANGE: Remove `get_data` and `validate_structured_result` from `StreamedRunResult` (pydantic#2445) * docs: add `griffe_warnings_deprecated` (pydantic#2444) * BREAKING CHANGE: Remove `format_as_xml` module (pydantic#2446) * BREAKING CHANGE: Remove `result_type` parameter and similar from `Agent` (pydantic#2441) * Deprecate `GoogleGLAProvider` and `GoogleVertexProvider` (pydantic#2450) * BREAKING CHANGE: drop 4 months old deprecation warnings (pydantic#2451) * Automatically use OpenAI strict mode for strict-compatible native output types (pydantic#2447) * Make `InlineDefsJsonSchemaTransformer` public (pydantic#2455) * Send `ThinkingPart`s back to Anthropic used through Bedrock (pydantic#2454) * Bump boto3 to support `AWS_BEARER_TOKEN_BEDROCK` API key env var (pydantic#2456) * Add new Heroku models (pydantic#2459) * Add `builtin_tools` to `Agent` (pydantic#2102) Co-authored-by: Marcelo Trylesinski <[email protected]> Co-authored-by: Douwe Maan <[email protected]> * Bump mcp-run-python (pydantic#2470) * Remove fail_under from top-level coverage config so <100% html-coverage step doesn't end CI run (pydantic#2475) * Add AbstractAgent, WrapperAgent, Agent.event_stream_handler, Toolset.id, Agent.override(tools=...) in preparation for Temporal (pydantic#2458) * Let toolsets be built dynamically based on run context (pydantic#2366) Co-authored-by: Douwe Maan <[email protected]> * Add ToolsetFunc to API docs (fix CI) (pydantic#2486) * tests: change time of evals example (pydantic#2501) * ci: remove html and xml reports (pydantic#2491) * fix: Add gpt-5 models to reasoning model detection for temperature parameter handling (pydantic#2483) Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Douwe Maan <[email protected]> Co-authored-by: Marcelo Trylesinski <[email protected]> * History processor replaces message history (pydantic#2324) Co-authored-by: Marcelo Trylesinski <[email protected]> * ci: split test suite (pydantic#2436) Co-authored-by: Douwe Maan <[email protected]> * ci: use the right install command (pydantic#2506) * Update config.yaml (pydantic#2514) * Skip testing flaky evals example (pydantic#2518) * Fix error when parsing usage details for video without audio track in Google models (pydantic#2507) * Make OpenAIResponsesModelSettings.openai_builtin_tools work again (pydantic#2520) * Let Agent be run in a Temporal workflow by moving model requests, tool calls, and MCP to Temporal activities (pydantic#2225) * Install only dev in CI (pydantic#2523) * Improve CLAUDE.md (pydantic#2524) * Add best practices regarding to coverage to CLAUDE.md (pydantic#2527) * Add support for `"openai-responses"` model inference string (pydantic#2528) Co-authored-by: Claude <[email protected]> * docs: Confident AI (pydantic#2529) * chore: mention what to do with the documentation when deprecating a class (pydantic#2530) * chore: drop hyperlint (pydantic#2531) * ci: improve matrix readability (pydantic#2532) * Add pip to dev deps for PyCharm (pydantic#2533) Co-authored-by: Marcelo Trylesinski <[email protected]> * Add genai-prices to dev deps and a basic test (pydantic#2537) * Add `--durations=100` to all pytest calls in CI (pydantic#2534) * Cleanup snapshot in test_evaluate_async_logfire (pydantic#2538) * Make some minor tweaks to the temporal docs (pydantic#2522) Co-authored-by: Douwe Maan <[email protected]> * Add new OpenAI GPT-5 models (pydantic#2503) * Fix `FallbackModel` to respect each model's model settings (pydantic#2540) * Add support for OpenAI verbosity parameter in Responses API (pydantic#2493) Co-authored-by: Claude <[email protected]> Co-authored-by: Douwe Maan <[email protected]> * Add `UsageLimits.count_tokens_before_request` using Gemini `count_tokens` API (pydantic#2137) Co-authored-by: Douwe Maan <[email protected]> * chore: Fix uv.lock (pydantic#2546) * Stop calling MCP server `get_tools` ahead of `agent run` span (pydantic#2545) * Disable instrumentation by default in tests (pydantic#2535) Co-authored-by: Marcelo Trylesinski <[email protected]> * Only wrap necessary parts of type aliases in forward annotations (pydantic#2548) * Remove anthropic-beta default header set in `AnthropicModel` (pydantic#2544) Co-authored-by: Marcelo Trylesinski <[email protected]> * docs: Clarify why AG-UI example links are on localhost (pydantic#2549) * chore: Fix path to agent class in CLAUDE.md (pydantic#2550) * Ignore leading whitespace when streaming from Qwen or DeepSeek (pydantic#2554) * Ask model to try again if it produced a response without text or tool calls, only thinking (pydantic#2556) Co-authored-by: Douwe Maan <[email protected]> * chore: Improve Temporal test to check trace as tree instead of list (pydantic#2559) * Fix: Forward max_uses parameter to Anthropic WebSearchTool (pydantic#2561) * Let message history end on ModelResponse and execute pending tool calls (pydantic#2562) * Fix type issues * skip tests requiring API keys * add `google-genai` dependency * add other provider deps * add pragma: no cover for untested logic --------- Co-authored-by: akenar <[email protected]> Co-authored-by: Tony Woland <[email protected]> Co-authored-by: Douwe Maan <[email protected]> Co-authored-by: Yi-Chen Lin <[email protected]> Co-authored-by: José I. Escudero <[email protected]> Co-authored-by: jescudero <[email protected]> Co-authored-by: Marcelo Trylesinski <[email protected]> Co-authored-by: William Easton <[email protected]> Co-authored-by: David Montague <[email protected]> Co-authored-by: Guillermo <[email protected]> Co-authored-by: Hamza Farhan <[email protected]> Co-authored-by: Mohamed Amine Zghal <[email protected]> Co-authored-by: Yinon Ehrlich <[email protected]> Co-authored-by: Matthew Brandman <[email protected]> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Douwe Maan <[email protected]> Co-authored-by: Alex Enrique <[email protected]> Co-authored-by: Jerry Yan <[email protected]> Co-authored-by: Claude <[email protected]> Co-authored-by: Mayank <[email protected]> Co-authored-by: Alex Hall <[email protected]> Co-authored-by: Jerry Lin <[email protected]> Co-authored-by: Raymond Xu <[email protected]> Co-authored-by: kauabh <[email protected]> Co-authored-by: Victorien <[email protected]> Co-authored-by: Ethan Brooks <[email protected]> Co-authored-by: eballesteros <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
openai_text_verbosity
setting for OpenAI Responses API modelsTest plan
Implementation Details
openai_text_verbosity: Literal['low', 'medium', 'high']
toOpenAIResponsesModelSettings
_responses_create
method to include verbosity in text config when specifiedThis addresses issue #2478 and provides the functionality requested in the GitHub issue with proper error handling and documentation.
🤖 Generated with Claude Code