fix(genai): propagate the stop instance attribute to the model#1818
Open
obchain (obchain) wants to merge 1 commit into
Open
fix(genai): propagate the stop instance attribute to the model#1818obchain (obchain) wants to merge 1 commit into
obchain (obchain) wants to merge 1 commit into
Conversation
`ChatGoogleGenerativeAI(stop=[...])` was ignored: `_build_base_generation_config` set `stop_sequences` solely from the per-call `stop` argument, with no fallback to `self.stop` (unlike `temperature`, `max_output_tokens`, `top_k`, etc., which all fall back to their instance attributes). As a result, stop sequences configured on the model only took effect when also passed to `invoke(..., stop=[...])`. Fall back to `self.stop` when no per-call `stop` is supplied. Closes langchain-ai#1586
Sai Teja Bandaru (saitejabandaru-in)
left a comment
There was a problem hiding this comment.
This is a solid and clean fix for the stop sequences propagation bug (#1586).
Using stop if stop is not None else self.stop correctly handles the case where stop is explicitly passed as an empty list [] at call time to override an instance-level self.stop configuration (which evaluates to [] and bypasses the fallback, as intended).
The unit test is comprehensive and covers the exact regression path. Verified the diff and this looks great!
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.
Why
Fixes #1586.
stopis a documented model parameter onChatGoogleGenerativeAI, but setting it at construction time is silently ignored:Root cause
_build_base_generation_configsetsstop_sequencesdirectly from the per-callstopargument:Every other parameter in that config falls back to its instance attribute (
kwargs.get("temperature", self.temperature),self.max_output_tokens,self.top_k, ...).stopis the only one that does not, soself.stopis never consulted.What
self.stopwhen no per-callstopis supplied:test_instance_stop_is_propagatedconfirming a model-levelstopreaches the generation config. The existingtest_kwargs_override_stopalready covers the per-call-override path, which remains unchanged.Areas requiring careful review
stopstill overrides the instance attribute (the existing override test passes). The instance attribute now only applies when no per-callstopis given.Disclaimer
AI agents were involved in drafting this contribution; the diagnosis, fix, and test were reviewed manually before submission.