Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/genai/langchain_google_genai/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2694,7 +2694,7 @@ def _build_base_generation_config(
config: dict[str, Any] = {
"candidate_count": self.n,
"temperature": kwargs.get("temperature", self.temperature),
"stop_sequences": stop,
"stop_sequences": stop if stop is not None else self.stop,
"max_output_tokens": kwargs.get(
"max_output_tokens", self.max_output_tokens
),
Expand Down
16 changes: 16 additions & 0 deletions libs/genai/tests/unit_tests/test_chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4363,6 +4363,22 @@ def test_kwargs_override_stop() -> None:
assert config.stop_sequences == ["me"]


def test_instance_stop_is_propagated() -> None:
"""Regression test for #1586.

The `stop` instance attribute must be propagated to the generation
config when no per-call `stop` is supplied.
"""
llm = ChatGoogleGenerativeAI(
model=MODEL_NAME, google_api_key=SecretStr(FAKE_API_KEY), stop=["model"]
)

msg = HumanMessage(content="test")
request = llm._prepare_request([msg])
config = request["config"]
assert config.stop_sequences == ["model"]


def test_kwargs_override_thinking_budget() -> None:
"""Test that thinking_budget can be overridden via kwargs."""
llm = ChatGoogleGenerativeAI(
Expand Down
Loading