Add conversation agent selector, use in conversation.process
service (#95462)
This commit is contained in:
parent
1a6c32f8e9
commit
a7dfe46fb1
3 changed files with 51 additions and 1 deletions
|
@ -20,4 +20,4 @@ process:
|
||||||
description: Assist engine to process your request
|
description: Assist engine to process your request
|
||||||
example: homeassistant
|
example: homeassistant
|
||||||
selector:
|
selector:
|
||||||
text:
|
conversation_agent:
|
||||||
|
|
|
@ -500,6 +500,34 @@ class ConstantSelector(Selector[ConstantSelectorConfig]):
|
||||||
return self.config["value"]
|
return self.config["value"]
|
||||||
|
|
||||||
|
|
||||||
|
class ConversationAgentSelectorConfig(TypedDict, total=False):
|
||||||
|
"""Class to represent a conversation agent selector config."""
|
||||||
|
|
||||||
|
language: str
|
||||||
|
|
||||||
|
|
||||||
|
@SELECTORS.register("conversation_agent")
|
||||||
|
class COnversationAgentSelector(Selector[ConversationAgentSelectorConfig]):
|
||||||
|
"""Selector for a conversation agent."""
|
||||||
|
|
||||||
|
selector_type = "conversation_agent"
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Optional("language"): str,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, config: ConversationAgentSelectorConfig) -> None:
|
||||||
|
"""Instantiate a selector."""
|
||||||
|
super().__init__(config)
|
||||||
|
|
||||||
|
def __call__(self, data: Any) -> str:
|
||||||
|
"""Validate the passed selection."""
|
||||||
|
agent: str = vol.Schema(str)(data)
|
||||||
|
return agent
|
||||||
|
|
||||||
|
|
||||||
class DateSelectorConfig(TypedDict):
|
class DateSelectorConfig(TypedDict):
|
||||||
"""Class to represent a date selector config."""
|
"""Class to represent a date selector config."""
|
||||||
|
|
||||||
|
|
|
@ -979,3 +979,25 @@ def test_constant_selector_schema_error(schema) -> None:
|
||||||
"""Test constant selector."""
|
"""Test constant selector."""
|
||||||
with pytest.raises(vol.Invalid):
|
with pytest.raises(vol.Invalid):
|
||||||
selector.validate_selector({"constant": schema})
|
selector.validate_selector({"constant": schema})
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("schema", "valid_selections", "invalid_selections"),
|
||||||
|
(
|
||||||
|
(
|
||||||
|
{},
|
||||||
|
("home_assistant", "2j4hp3uy4p87wyrpiuhk34"),
|
||||||
|
(None, True, 1),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
{"language": "nl"},
|
||||||
|
("home_assistant", "2j4hp3uy4p87wyrpiuhk34"),
|
||||||
|
(None, True, 1),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_conversation_agent_selector_schema(
|
||||||
|
schema, valid_selections, invalid_selections
|
||||||
|
) -> None:
|
||||||
|
"""Test conversation agent selector."""
|
||||||
|
_test_selector("conversation_agent", schema, valid_selections, invalid_selections)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue