Add base prompt for LLMs (#118592)

This commit is contained in:
Paulus Schoutsen 2024-06-01 00:21:37 -04:00 committed by GitHub
parent dfb407728f
commit f3b20d30ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 16 deletions

View File

@ -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,

View File

@ -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(
{

View File

@ -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") }}.
"""

View File

@ -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.
<no_api_prompt>
''',
'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.
<no_api_prompt>
''',
'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.
<api_prompt>
''',
'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.
<api_prompt>
''',
'role': 'user',