Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,10 @@ def _process_thinking_config(generation_kwargs: dict[str, Any]) -> dict[str, Any
thinking_budget = -1

# Create thinking config
thinking_config = types.ThinkingConfig(thinking_budget=thinking_budget, include_thoughts=True)
# When thinking_budget is 0, thinking is disabled so include_thoughts must be False
thinking_config = types.ThinkingConfig(
thinking_budget=thinking_budget, include_thoughts=thinking_budget != 0
)
generation_kwargs["thinking_config"] = thinking_config

if "thinking_level" in generation_kwargs:
Expand Down
4 changes: 4 additions & 0 deletions integrations/google_genai/tests/test_chat_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1508,23 +1508,27 @@ def test_process_thinking_budget(monkeypatch):
assert "thinking_budget" not in result
assert "thinking_config" in result
assert result["thinking_config"].thinking_budget == 1024
assert result["thinking_config"].include_thoughts is True
# Other kwargs should be preserved
assert result["temperature"] == 0.7

# Test dynamic allocation (-1)
generation_kwargs = {"thinking_budget": -1}
result = GoogleGenAIChatGenerator._process_thinking_config(generation_kwargs.copy())
assert result["thinking_config"].thinking_budget == -1
assert result["thinking_config"].include_thoughts is True

# Test zero (disable thinking)
generation_kwargs = {"thinking_budget": 0}
result = GoogleGenAIChatGenerator._process_thinking_config(generation_kwargs.copy())
assert result["thinking_config"].thinking_budget == 0
assert result["thinking_config"].include_thoughts is False

# Test large value
generation_kwargs = {"thinking_budget": 24576}
result = GoogleGenAIChatGenerator._process_thinking_config(generation_kwargs.copy())
assert result["thinking_config"].thinking_budget == 24576
assert result["thinking_config"].include_thoughts is True

# Test when thinking_budget is not present
generation_kwargs = {"temperature": 0.5}
Expand Down