Skip to content

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ryx2
Copy link

@ryx2 ryx2 commented Aug 10, 2025

Summary

  • Implements the openai_text_verbosity setting for OpenAI Responses API models
  • Allows users to control response verbosity with 'low', 'medium', or 'high' values
  • Adds proper integration with the OpenAI Responses API text configuration

Test plan

  • Added unit test for verbosity parameter functionality
  • Verified syntax and basic functionality with test script
  • Follows existing code patterns and conventions from the codebase

Implementation Details

  • Added openai_text_verbosity: Literal['low', 'medium', 'high'] to OpenAIResponsesModelSettings
  • Modified _responses_create method to include verbosity in text config when specified
  • Added comprehensive test case to verify the feature works correctly

This addresses issue #2478 and provides the functionality requested in the GitHub issue with proper error handling and documentation.

🤖 Generated with Claude Code

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]>
@medaminezghal
Copy link
Contributor

@ryx2 Could I use your PR to enhance this PR?

ryx2 and others added 5 commits August 12, 2025 14:48
- 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]>
@ryx2
Copy link
Author

ryx2 commented Aug 13, 2025

@DouweM cool to upgrade openai to 1.99.9?

@ryx2
Copy link
Author

ryx2 commented Aug 13, 2025

@DouweM why are these unrelated tests failing in CI?

@ryx2 ryx2 requested a review from DouweM August 13, 2025 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants