Repository navigation
fix(genai): omit tools and system instruction when cached_content is provided - #2591
Closed
kishansaaai wants to merge 1 commit into
Closed
kishansaaai wants to merge 1 commit into
kishansaaai wants to merge 1 commit into
Conversation
Collaborator
|
Superseded by the consolidated implementation in #2597: #2597 . The release branch includes this fix or its deduplicated equivalent, with additional regression coverage. Closing the overlapping source PR to keep review in one place. This does not mean the release is merged or shipped: #2597 remains draft pending exact-head CI, independent review, and unresolved security sign-off. |
2 of 3 tasks
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
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
In Google GenAI, passing
system_instruction,tools, ortool_configin requests when usingcached_contentis rejected by the Gemini API with:because those parameters must be defined inside the cache itself (per https://ai.google.dev/gemini-api/docs/caching).
In v2 handlers (
instructor/v2/providers/genai/handlers.py),GenAIToolsHandler.prepare_requestandGenAIStructuredOutputsHandler.prepare_requestpreviously builtbase_configunconditionally, includingsystem_instruction,tools, andtool_configeven when the caller specifiedcached_content.This change:
_extract_cached_contentonGenAIHandlerBaseto detectcached_contentfromconfig(as a dict orGenerateContentConfiginstance) or top-levelkwargs.system_instruction,tools, andtool_configfrombase_configinGenAIToolsHandler.prepare_requestwhencached_contentis present.system_instructionfrombase_configinGenAIStructuredOutputsHandler.prepare_requestwhencached_contentis present (preservingresponse_mime_typeandresponse_schema).system_instructionin_prepare_without_response_modelwhencached_contentis present.cached_contentkwargs are merged intoconfiginupdate_genai_kwargs.tests/v2/test_genai_integration.pyverifying thattools,tool_config, andsystem_instructionare omitted whencached_contentis supplied in bothMode.TOOLSandMode.JSON.Issue ticket number and link
Fixes #2580
Checklist before requesting a review