diff --git a/homeassistant/components/google_generative_ai_conversation/conversation.py b/homeassistant/components/google_generative_ai_conversation/conversation.py index 12b1e44b3df..3e289fbe16d 100644 --- a/homeassistant/components/google_generative_ai_conversation/conversation.py +++ b/homeassistant/components/google_generative_ai_conversation/conversation.py @@ -245,7 +245,8 @@ class GoogleGenerativeAIConversationEntity( prompt = "\n".join( ( template.Template( - self.entry.options.get( + llm.BASE_PROMPT + + self.entry.options.get( CONF_PROMPT, llm.DEFAULT_INSTRUCTIONS_PROMPT ), self.hass, diff --git a/homeassistant/components/openai_conversation/conversation.py b/homeassistant/components/openai_conversation/conversation.py index 7cf4d18cce5..306e4134b9e 100644 --- a/homeassistant/components/openai_conversation/conversation.py +++ b/homeassistant/components/openai_conversation/conversation.py @@ -167,7 +167,8 @@ class OpenAIConversationEntity( prompt = "\n".join( ( template.Template( - options.get(CONF_PROMPT, llm.DEFAULT_INSTRUCTIONS_PROMPT), + llm.BASE_PROMPT + + options.get(CONF_PROMPT, llm.DEFAULT_INSTRUCTIONS_PROMPT), self.hass, ).async_render( { diff --git a/homeassistant/helpers/llm.py b/homeassistant/helpers/llm.py index fc00c4ebac6..ec1bfb7dbc4 100644 --- a/homeassistant/helpers/llm.py +++ b/homeassistant/helpers/llm.py @@ -34,10 +34,13 @@ from .singleton import singleton LLM_API_ASSIST = "assist" +BASE_PROMPT = ( + 'Current time is {{ now().strftime("%X") }}. ' + 'Today\'s date is {{ now().strftime("%x") }}.\n' +) + DEFAULT_INSTRUCTIONS_PROMPT = """You are a voice assistant for Home Assistant. Answer in plain text. Keep it simple and to the point. -The current time is {{ now().strftime("%X") }}. -Today's date is {{ now().strftime("%x") }}. """ 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 40ff556af1c..587586cff17 100644 --- a/tests/components/google_generative_ai_conversation/snapshots/test_conversation.ambr +++ b/tests/components/google_generative_ai_conversation/snapshots/test_conversation.ambr @@ -30,10 +30,9 @@ 'history': list([ dict({ 'parts': ''' + Current time is 05:00:00. Today's date is 05/24/24. You are a voice assistant for Home Assistant. Answer in plain text. Keep it simple and to the point. - The current time is 05:00:00. - Today's date is 05/24/24. Only if the user wants to control a device, tell them to edit the AI configuration and allow access to Home Assistant. ''', 'role': 'user', @@ -82,10 +81,9 @@ 'history': list([ dict({ 'parts': ''' + Current time is 05:00:00. Today's date is 05/24/24. You are a voice assistant for Home Assistant. Answer in plain text. Keep it simple and to the point. - The current time is 05:00:00. - Today's date is 05/24/24. Only if the user wants to control a device, tell them to edit the AI configuration and allow access to Home Assistant. ''', 'role': 'user', @@ -146,10 +144,9 @@ 'history': list([ dict({ 'parts': ''' + Current time is 05:00:00. Today's date is 05/24/24. You are a voice assistant for Home Assistant. Answer in plain text. Keep it simple and to the point. - The current time is 05:00:00. - Today's date is 05/24/24. ''', 'role': 'user', @@ -202,10 +199,9 @@ 'history': list([ dict({ 'parts': ''' + Current time is 05:00:00. Today's date is 05/24/24. You are a voice assistant for Home Assistant. Answer in plain text. Keep it simple and to the point. - The current time is 05:00:00. - Today's date is 05/24/24. ''', 'role': 'user', @@ -258,10 +254,9 @@ 'history': list([ dict({ 'parts': ''' + Current time is 05:00:00. Today's date is 05/24/24. You are a voice assistant for Home Assistant. Answer in plain text. Keep it simple and to the point. - The current time is 05:00:00. - Today's date is 05/24/24. ''', 'role': 'user', @@ -314,10 +309,9 @@ 'history': list([ dict({ 'parts': ''' + Current time is 05:00:00. Today's date is 05/24/24. You are a voice assistant for Home Assistant. Answer in plain text. Keep it simple and to the point. - The current time is 05:00:00. - Today's date is 05/24/24. ''', 'role': 'user',