From 34640ea7357637dbc00c160d42dcf15839ae96a5 Mon Sep 17 00:00:00 2001 From: Denis Shulyaka Date: Thu, 2 Oct 2025 11:38:31 +0300 Subject: [PATCH] Disable thinking for unsupported gemini models (#153415) --- .../google_generative_ai_conversation/entity.py | 9 ++++++++- .../google_generative_ai_conversation/test_tts.py | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/google_generative_ai_conversation/entity.py b/homeassistant/components/google_generative_ai_conversation/entity.py index 45ef4aad2d44..74b76d9bb834 100644 --- a/homeassistant/components/google_generative_ai_conversation/entity.py +++ b/homeassistant/components/google_generative_ai_conversation/entity.py @@ -620,6 +620,13 @@ class GoogleGenerativeAILLMBaseEntity(Entity): def create_generate_content_config(self) -> GenerateContentConfig: """Create the GenerateContentConfig for the LLM.""" options = self.subentry.data + model = options.get(CONF_CHAT_MODEL, RECOMMENDED_CHAT_MODEL) + thinking_config: ThinkingConfig | None = None + if model.startswith("models/gemini-2.5") and not model.endswith( + ("tts", "image", "image-preview") + ): + thinking_config = ThinkingConfig(include_thoughts=True) + return GenerateContentConfig( temperature=options.get(CONF_TEMPERATURE, RECOMMENDED_TEMPERATURE), top_k=options.get(CONF_TOP_K, RECOMMENDED_TOP_K), @@ -652,7 +659,7 @@ class GoogleGenerativeAILLMBaseEntity(Entity): ), ), ], - thinking_config=ThinkingConfig(include_thoughts=True), + thinking_config=thinking_config, ) diff --git a/tests/components/google_generative_ai_conversation/test_tts.py b/tests/components/google_generative_ai_conversation/test_tts.py index 271a209f79f3..c55a2a2795d3 100644 --- a/tests/components/google_generative_ai_conversation/test_tts.py +++ b/tests/components/google_generative_ai_conversation/test_tts.py @@ -208,7 +208,7 @@ async def test_tts_service_speak( threshold=RECOMMENDED_HARM_BLOCK_THRESHOLD, ), ], - thinking_config=types.ThinkingConfig(include_thoughts=True), + thinking_config=None, ), ) @@ -277,6 +277,6 @@ async def test_tts_service_speak_error( threshold=RECOMMENDED_HARM_BLOCK_THRESHOLD, ), ], - thinking_config=types.ThinkingConfig(include_thoughts=True), + thinking_config=None, ), )