diff --git a/homeassistant/components/google_generative_ai_conversation/config_flow.py b/homeassistant/components/google_generative_ai_conversation/config_flow.py index 50b626f553c..b559888cc5f 100644 --- a/homeassistant/components/google_generative_ai_conversation/config_flow.py +++ b/homeassistant/components/google_generative_ai_conversation/config_flow.py @@ -181,8 +181,7 @@ async def google_generative_ai_config_option_schema( schema = { vol.Optional( CONF_PROMPT, - description={"suggested_value": options.get(CONF_PROMPT)}, - default=DEFAULT_PROMPT, + description={"suggested_value": options.get(CONF_PROMPT, DEFAULT_PROMPT)}, ): TemplateSelector(), vol.Optional( CONF_LLM_HASS_API, diff --git a/homeassistant/components/google_generative_ai_conversation/conversation.py b/homeassistant/components/google_generative_ai_conversation/conversation.py index ad50c544ac7..21d26ab5616 100644 --- a/homeassistant/components/google_generative_ai_conversation/conversation.py +++ b/homeassistant/components/google_generative_ai_conversation/conversation.py @@ -205,15 +205,6 @@ class GoogleGenerativeAIConversationEntity( messages = [{}, {}] try: - prompt = template.Template( - self.entry.options.get(CONF_PROMPT, DEFAULT_PROMPT), self.hass - ).async_render( - { - "ha_name": self.hass.config.location_name, - }, - parse_result=False, - ) - if llm_api: empty_tool_input = llm.ToolInput( tool_name="", @@ -226,9 +217,24 @@ class GoogleGenerativeAIConversationEntity( device_id=user_input.device_id, ) - prompt = ( - await llm_api.async_get_api_prompt(empty_tool_input) + "\n" + prompt + api_prompt = await llm_api.async_get_api_prompt(empty_tool_input) + + else: + api_prompt = llm.PROMPT_NO_API_CONFIGURED + + prompt = "\n".join( + ( + api_prompt, + template.Template( + self.entry.options.get(CONF_PROMPT, DEFAULT_PROMPT), self.hass + ).async_render( + { + "ha_name": self.hass.config.location_name, + }, + parse_result=False, + ), ) + ) except TemplateError as err: LOGGER.error("Error rendering prompt: %s", err) diff --git a/tests/components/google_generative_ai_conversation/snapshots/test_conversation.ambr b/tests/components/google_generative_ai_conversation/snapshots/test_conversation.ambr index ebc918bbf31..112e1f91b55 100644 --- a/tests/components/google_generative_ai_conversation/snapshots/test_conversation.ambr +++ b/tests/components/google_generative_ai_conversation/snapshots/test_conversation.ambr @@ -29,7 +29,10 @@ dict({ 'history': list([ dict({ - 'parts': 'Answer in plain text. Keep it simple and to the point.', + 'parts': ''' + Only if the user wants to control a device, tell them to edit the AI configuration and allow access to Home Assistant. + Answer in plain text. Keep it simple and to the point. + ''', 'role': 'user', }), dict({ @@ -79,7 +82,10 @@ dict({ 'history': list([ dict({ - 'parts': 'Answer in plain text. Keep it simple and to the point.', + 'parts': ''' + Only if the user wants to control a device, tell them to edit the AI configuration and allow access to Home Assistant. + Answer in plain text. Keep it simple and to the point. + ''', 'role': 'user', }), dict({