Skip to content

Commit

Permalink
Add no-API LLM prompt back to Google (#118082)
Browse files Browse the repository at this point in the history
* Add no-API LLM prompt back

* Use string join
  • Loading branch information
balloob committed May 25, 2024
1 parent 86a24cc commit c59d4f9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,6 @@ async def async_process(
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="",
Expand All @@ -226,9 +217,24 @@ async def async_process(
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit c59d4f9

Please sign in to comment.