-
-
Notifications
You must be signed in to change notification settings - Fork 869
fix(genai): handle response_model=None for GenAI modes #1694
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
Conversation
Fixes issue where response_model=None would fail for Google GenAI provider with error ''Models.generate_content() got an unexpected keyword argument messages''. The bug was in instructor/process_response.py where the response_model=None code path (lines 1094-1121) handled Cohere and Anthropic modes but was missing GenAI mode handling. When response_model is provided, GenAI modes properly convert OpenAI-style messages to GenAI-style contents, but this conversion was missing for the response_model=None case. The fix adds GenAI mode handling that: 1. Converts OpenAI-style messages to GenAI-style contents using convert_to_genai_messages() 2. Extracts multimodal content using extract_genai_multimodal_content() 3. Handles system messages by extracting them and creating proper config Fixes #1690 Co-authored-by: Jason Liu <[email protected]>
Deploying with
|
Status | Name | Latest Commit | Preview URL | Updated (UTC) |
---|---|---|---|---|
✅ Deployment successful! View logs |
instructor | a95e3ae | Commit Preview URL Branch Preview URL |
Jul 11 2025, 07:55 PM |
Claude finished @jxnl's task —— View job PR Review Analysis - Complete ✅I've completed a comprehensive review of the PR that fixes GenAI modes when ✅ Code Quality and Best PracticesStrengths:
Code Structure:
✅ Correctness and Bug AnalysisThe Fix Addresses the Root Cause:
Implementation Details:
✅ Test Coverage AssessmentComprehensive Testing:
Test Quality:
✅ Performance Considerations
✅ Security Considerations
🔍 Minor ObservationsPotential Areas for Improvement:
Edge Case Considerations:
✅ Overall AssessmentVerdict: Excellent Fix ⭐⭐⭐⭐⭐ This is a well-implemented bug fix that:
Recommendations:
Files Changed:
|
Claude finished @jxnl's task —— View job PR Review AnalysisReviewing PR for code quality, potential bugs, performance, security, and test coverage. Todo List:
Code Review Results✅ Fix Quality & CorrectnessThe fix correctly addresses the reported issue where Key changes in
✅ Code Quality & Best Practices
✅ Test CoverageThe test file
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important
Looks good to me! 👍
Reviewed everything up to a08a408 in 1 minute and 59 seconds. Click for details.
- Reviewed
166
lines of code in3
files - Skipped
0
files when reviewing. - Skipped posting
3
draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. instructor/process_response.py:1113
- Draft comment:
Nice fix for handling GenAI modes when response_model is None. The branch cleanly converts messages to GenAI contents, extracts multimodal content, and sets up the config if a system message is found. Consider adding a brief note on the rationale for only updating config if 'system' isn’t already provided. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 0% vs. threshold = 85% The comment is purely informative and doesn't suggest any clear code changes. It's mostly just describing what the code does, which is already clear from the code comments. The suggestion to add a note about the rationale is a request for explanation rather than a concrete code improvement. According to the rules, we should not make purely informative comments or ask for explanations. The code does seem to have a specific logic around system messages - maybe there is a potential bug or improvement needed here that I'm missing? No, the system message handling is straightforward and well-commented. If there was a bug, the comment doesn't identify it. The comment is just descriptive and asking for more documentation. The comment should be deleted as it is purely informative and doesn't suggest any concrete code changes. The code is already well-commented and the logic is clear.
2. test_fix_local.py:24
- Draft comment:
Test script looks functional. For better robustness, consider adding assertions to verify that the response structure (e.g., presence of 'contents' and absence of 'messages') meets expectations in addition to printing the result. - Reason this comment was not posted:
Confidence changes required:80%
<= threshold85%
None
3. tests/llm/test_genai/test_response_model_none.py:13
- Draft comment:
Good use of parameterized tests to verify behavior for both GENAI_TOOLS and GENAI_STRUCTURED_OUTPUTS modes. The tests correctly assert that the raw response is returned and isn’t parsed as a Pydantic model. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%
<= threshold85%
This comment is purely informative and does not provide any actionable feedback or suggestions for improvement. It simply praises the use of parameterized tests without offering any constructive criticism or specific guidance.
Workflow ID: wflow_DhCrfStP580RI5Vq
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Fixes issue where response_model=None would fail for Google GenAI provider with error "Models.generate_content() got an unexpected keyword argument 'messages'".
The bug was in instructor/process_response.py where the response_model=None code path handled Cohere and Anthropic modes but was missing GenAI mode handling. This fix adds proper message to contents conversion for GenAI modes.
Fixes #1690
Generated with Claude Code
Important
Fixes handling of
response_model=None
for GenAI modes ininstructor/process_response.py
and adds tests to verify the fix.response_model=None
for GenAI modes ininstructor/process_response.py
.test_fix_local.py
to demonstrate the fix forresponse_model=None
.test_response_model_none.py
intests/llm/test_genai/
to verify GenAI client behavior withresponse_model=None
.This description was created by
for a08a408. You can customize this summary. It will automatically update as commits are pushed.