Add no-API LLM prompt back to Google (#118082)

* Add no-API LLM prompt back

* Use string join
This commit is contained in:
Paulus Schoutsen 2024-05-25 00:00:04 -04:00 committed by GitHub
parent 86a24cc3b9
commit c59d4f9bba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 15 deletions

View File

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

View File

@ -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,8 +217,23 @@ 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:

View File

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