-
Notifications
You must be signed in to change notification settings - Fork 16
Add response_format parameter support for structured output #60
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
Add response_format parameter support for structured output #60
Conversation
|
Hi @YouNeedCryDear! 👋 I hope you're doing well! I wanted to gently follow up on this PR that adds Why this matters: What's been validated:
This follows the same parameter pattern as other recent enhancements and should be a straightforward addition to the SDK's capabilities. Would you have a chance to take a look when you get a moment? I'm happy to address any feedback or questions you might have! Thanks so much for maintaining this project! 🙏 |
|
@fede-kamel Why do we need |
Response to Review Feedback@YouNeedCryDear Changes Made
Why This ApproachThis makes the OCI implementation consistent with other LangChain providers (OpenAI, Anthropic, etc.) where response format parameters are handled through Real-World TestingTo verify the functionality still works correctly after these changes, I tested with real OCI Generative AI API calls: With Meta Llama 4 model: llm = ChatOCIGenAI(
model_id="meta.llama-4-maverick-17b-128e-instruct-fp8",
model_kwargs={"response_format": {"type": "JSON_OBJECT"}},
# ... other config
)
response = llm.invoke("Create JSON with name and age for Alice who is 30")
# Returns: {"name": "Alice", "age": 30}Tested successfully with:
The response format functionality works perfectly and enforces proper JSON output from the models. This change maintains backward compatibility while providing a cleaner, more consistent API design. Users can still access all the structured output features through |
|
Hi @YouNeedCryDear, just following up—this PR is ready for another look whenever you have a moment. Appreciate your previous feedback! |
|
@fede-kamel Sorry I don't see any new changes after our discussion. |
Implements response_format parameter to enable JSON mode and JSON schema output formatting for both Meta Llama and Cohere models. This allows users to leverage structured output capabilities via with_structured_output() and direct response_format configuration. Changes: - Add response_format field to OCIGenAIBase with comprehensive documentation - Implement response_format handling in ChatOCIGenAI._prepare_request method - Support response_format via class initialization, bind(), and model_kwargs - Add comprehensive unit tests covering all configuration methods - Add integration tests validating end-to-end functionality with real API calls The implementation ensures response_format is properly passed to both GenericChatRequest (Meta Llama) and CohereChatRequest (Cohere) models. Fixes oracle#33
- Remove response_format field from OCIGenAIBase class - Remove special handling in ChatOCIGenAI._prepare_request() - Update tests to use model_kwargs for response_format - Maintain functionality while ensuring consistency with other LangChain providers This addresses the reviewer's concern about having response_format as a class field instead of handling it through model_kwargs like other providers.
299d2ca to
7c08d7c
Compare
|
Hi @YouNeedCryDear! 👋 The changes have now been pushed to the PR. I apologize for the confusion - the commit addressing your feedback was created locally but wasn't pushed to GitHub until now. Changes Applied:
The functionality remains the same, but now follows the same pattern as other LangChain providers by handling You should now see two commits in the PR:
Ready for another review when you have a chance. Thanks for your patience! |
- Fix line length violations by splitting long strings - Auto-fix import ordering and remove unused imports - Run ruff format on all modified files - All ruff and mypy checks now pass
|
The CI failures in All
The |
Summary
Implements response_format parameter to enable JSON mode and JSON schema output formatting for both Meta Llama and Cohere models. This allows users to leverage structured output capabilities via
with_structured_output()and direct response_format configuration.Changes
Implementation Details
The implementation ensures response_format is properly passed to both GenericChatRequest (Meta Llama) and CohereChatRequest (Cohere) models by adding the parameter to the model_kwargs in the _prepare_request method.
Testing
Unit Tests: 9/9 tests passing
Integration Tests: 10/10 tests passing with real OCI API calls
Fixes
Fixes #33
Breaking Changes
None - this is a new feature that is fully backward compatible.