-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: preserve reasoning_effort parameter for GPT-5 models #241
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
base: main
Are you sure you want to change the base?
fix: preserve reasoning_effort parameter for GPT-5 models #241
Conversation
✅ Fixed original issue google#237 - reasoning_effort now works correctly ✅ Unit tests: 4/4 passing ✅ Integration test: reaches API successfully (quota error proves fix works) ✅ Backward compatibility maintained Fixes google#237
- Remove trailing whitespace throughout test files - Fix import order (unittest.mock before third-party imports) - Remove unused imports (pytest, Mock, json) - Remove unused variables and broad exception catching - Delete test_mock_verification.py (lint-problematic file) - Maintain all test functionality while achieving lint compliance All core functionality tested and working
|
@aksg87 I have worked on resolving the issue, you can check it out. |
|
Your branch is 1 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
|
Your branch is 2 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
|
Your branch is 1 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
|
Your branch is 1 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
|
Your branch is 3 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
|
Your branch is 4 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
|
Your branch is 8 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
|
Your branch is 10 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
Description
Fixes #237 - GPT-5-mini reasoning_effort Parameter Issue
Problem
When using
reasoning_effortparameter with GPT-5 models, the following error occurred:Exception: OpenAI API error: Completions.create() got an unexpected keyword argument 'reasoning'This prevented users from utilizing GPT-5's reasoning capabilities through LangExtract, making the library incompatible with OpenAI's latest models.
Root Cause
The
_normalize_reasoning_params()method insrc/langextract/providers/openai.pyincorrectly transformed the parameter from:{"reasoning_effort": "minimal"} # ✅ Expected by OpenAI APIInto:
{"reasoning": {"effort": "minimal"}} # ❌ Invalid nested structureThis transformation caused OpenAI's API to reject the request with an "unexpected keyword argument" error.
Solution
_normalize_reasoning_params()to detect GPT-5 models and preservereasoning_effortas a top-level parametergpt-5,gpt-5-mini,gpt-5-nanovariantsverbosityparameter support for GPT-5 modelsTechnical Changes
File:
src/langextract/providers/openai.py_normalize_reasoning_params()method with GPT-5 model detection_process_single_prompt()to pass throughreasoning_effortandverbosityinfer()method to collect GPT-5-specific parametersFile:
tests/test_gpt5_reasoning_fix.py(new)Impact
How Has This Been Tested?
Unit Testing
`$ python -m pytest tests/test_gpt5_reasoning_fix.py -v
platform win32 -- Python 3.12.10, pytest-8.4.2, pluggy-1.6.0
collected 4 items
tests/test_gpt5_reasoning_fix.py::TestGPT5ReasoningEffort::test_gpt5_reasoning_effort_preserved PASSED [ 25%]
tests/test_gpt5_reasoning_fix.py::TestGPT5ReasoningEffort::test_gpt4_reasoning_effort_removed PASSED [ 50%]
tests/test_gpt5_reasoning_fix.py::TestGPT5ReasoningEffort::test_gpt5_variants_supported PASSED [ 75%]
tests/test_gpt5_reasoning_fix.py::TestGPT5ReasoningEffort::test_api_call_with_reasoning_effort PASSED [100%]
========== 4 passed in 6.89s ==========`
Checklist
Integration Testing
Before Fix:
Exception: OpenAI API error: Completions.create() got an unexpected keyword argument 'reasoning'After Fix:
$ python test_integration_fix.py LangExtract: model=gpt-5-mini [00:04]