Update LLM prompt to improve quality for local LLMs (#122746)

This commit is contained in:
Allen Porter 2024-07-29 03:04:23 -07:00 committed by GitHub
parent 85aca4f095
commit e5bb1b2cc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 52 additions and 69 deletions

View File

@ -324,8 +324,7 @@ class AssistAPI(API):
( (
"When controlling Home Assistant always call the intent tools. " "When controlling Home Assistant always call the intent tools. "
"Use HassTurnOn to lock and HassTurnOff to unlock a lock. " "Use HassTurnOn to lock and HassTurnOff to unlock a lock. "
"When controlling a device, prefer passing just its name and its domain " "When controlling a device, prefer passing just name and domain. "
"(what comes before the dot in its entity id). "
"When controlling an area, prefer passing just area name and domain." "When controlling an area, prefer passing just area name and domain."
) )
] ]
@ -363,7 +362,7 @@ class AssistAPI(API):
prompt.append( prompt.append(
"An overview of the areas and the devices in this smart home:" "An overview of the areas and the devices in this smart home:"
) )
prompt.append(yaml.dump(exposed_entities)) prompt.append(yaml.dump(list(exposed_entities.values())))
return "\n".join(prompt) return "\n".join(prompt)
@ -477,6 +476,7 @@ def _get_exposed_entities(
info: dict[str, Any] = { info: dict[str, Any] = {
"names": ", ".join(names), "names": ", ".join(names),
"domain": state.domain,
"state": state.state, "state": state.state,
} }

View File

@ -22,7 +22,6 @@ from homeassistant.helpers import (
selector, selector,
) )
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from homeassistant.util import yaml
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -506,74 +505,58 @@ async def test_assist_api_prompt(
suggested_area="Test Area 2", suggested_area="Test Area 2",
) )
) )
exposed_entities_prompt = """An overview of the areas and the devices in this smart home:
exposed_entities = llm._get_exposed_entities(hass, llm_context.assistant) - names: Kitchen
assert exposed_entities == { domain: light
"light.1": { state: 'on'
"areas": "Test Area 2", attributes:
"names": "1", temperature: '0.9'
"state": "unavailable", humidity: '65'
}, - names: Living Room
entry1.entity_id: { domain: light
"names": "Kitchen", state: 'on'
"state": "on", areas: Test Area, Alternative name
"attributes": {"temperature": "0.9", "humidity": "65"}, - names: Test Device
}, domain: light
entry2.entity_id: { state: unavailable
"areas": "Test Area, Alternative name", areas: Test Area, Alternative name
"names": "Living Room", - names: Test Service
"state": "on", domain: light
}, state: unavailable
"light.test_device": { areas: Test Area, Alternative name
"areas": "Test Area, Alternative name", - names: Test Service
"names": "Test Device", domain: light
"state": "unavailable", state: unavailable
}, areas: Test Area, Alternative name
"light.test_device_2": { - names: Test Service
"areas": "Test Area 2", domain: light
"names": "Test Device 2", state: unavailable
"state": "unavailable", areas: Test Area, Alternative name
}, - names: Test Device 2
"light.test_device_3": { domain: light
"areas": "Test Area 2", state: unavailable
"names": "Test Device 3", areas: Test Area 2
"state": "unavailable", - names: Test Device 3
}, domain: light
"light.test_device_4": { state: unavailable
"areas": "Test Area 2", areas: Test Area 2
"names": "Test Device 4", - names: Test Device 4
"state": "unavailable", domain: light
}, state: unavailable
"light.test_service": { areas: Test Area 2
"areas": "Test Area, Alternative name", - names: Unnamed Device
"names": "Test Service", domain: light
"state": "unavailable", state: unavailable
}, areas: Test Area 2
"light.test_service_2": { - names: '1'
"areas": "Test Area, Alternative name", domain: light
"names": "Test Service", state: unavailable
"state": "unavailable", areas: Test Area 2
}, """
"light.test_service_3": {
"areas": "Test Area, Alternative name",
"names": "Test Service",
"state": "unavailable",
},
"light.unnamed_device": {
"areas": "Test Area 2",
"names": "Unnamed Device",
"state": "unavailable",
},
}
exposed_entities_prompt = (
"An overview of the areas and the devices in this smart home:\n"
+ yaml.dump(exposed_entities)
)
first_part_prompt = ( first_part_prompt = (
"When controlling Home Assistant always call the intent tools. " "When controlling Home Assistant always call the intent tools. "
"Use HassTurnOn to lock and HassTurnOff to unlock a lock. " "Use HassTurnOn to lock and HassTurnOff to unlock a lock. "
"When controlling a device, prefer passing just its name and its domain " "When controlling a device, prefer passing just name and domain. "
"(what comes before the dot in its entity id). "
"When controlling an area, prefer passing just area name and domain." "When controlling an area, prefer passing just area name and domain."
) )
no_timer_prompt = "This device is not able to start timers." no_timer_prompt = "This device is not able to start timers."