mirror of
https://github.com/home-assistant/core.git
synced 2026-09-24 07:25:52 -05:00
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
"""LLM tools for the climate integration."""
|
|
|
|
from homeassistant.components.homeassistant import async_should_expose
|
|
from homeassistant.components.llm import LLMTools
|
|
from homeassistant.core import HomeAssistant, callback
|
|
from homeassistant.helpers import intent
|
|
from homeassistant.helpers.llm import (
|
|
LLM_API_ASSIST,
|
|
IntentTool,
|
|
LLMContext,
|
|
Tool,
|
|
ToolAnnotations,
|
|
)
|
|
|
|
from .const import DOMAIN, INTENT_SET_TEMPERATURE
|
|
|
|
# Each intent sets a value on the user's own entities, so calling one again
|
|
# with the same arguments has no further effect.
|
|
LLM_ANNOTATIONS = ToolAnnotations(idempotent=True, open_world=False)
|
|
|
|
# Intents owned by this integration that are exposed as LLM tools, with the
|
|
# title shown for each.
|
|
LLM_INTENTS = {
|
|
INTENT_SET_TEMPERATURE: "Set temperature",
|
|
}
|
|
|
|
|
|
@callback
|
|
def async_get_tools(
|
|
hass: HomeAssistant, llm_context: LLMContext, api_id: str
|
|
) -> LLMTools | None:
|
|
"""Return LLM tools for the integration's intents when its domain is exposed."""
|
|
if api_id != LLM_API_ASSIST:
|
|
return None
|
|
|
|
if not llm_context.assistant:
|
|
return None
|
|
|
|
if not any(
|
|
async_should_expose(hass, llm_context.assistant, state.entity_id)
|
|
for state in hass.states.async_all(DOMAIN)
|
|
):
|
|
return None
|
|
|
|
tools: list[Tool] = [
|
|
IntentTool(
|
|
f"{DOMAIN}__{handler.intent_type}",
|
|
handler,
|
|
title=LLM_INTENTS[handler.intent_type],
|
|
integration=DOMAIN,
|
|
annotations=LLM_ANNOTATIONS,
|
|
)
|
|
for handler in intent.async_get(hass)
|
|
if handler.intent_type in LLM_INTENTS
|
|
]
|
|
return LLMTools(tools=tools)
|