From f2bd122fde12f20dc8cf1189d6cb24254c7801fd Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Wed, 19 Jul 2023 09:03:53 +0200 Subject: [PATCH] Clean up conversation agent attribution (#96883) * Clean up conversation agent attribution * Clean up google_generative_ai_conversation as well --- .../components/conversation/__init__.py | 24 ------------ .../components/conversation/agent.py | 14 +------ .../google_assistant_sdk/__init__.py | 8 ---- .../__init__.py | 8 ---- .../openai_conversation/__init__.py | 5 --- tests/components/conversation/__init__.py | 5 --- tests/components/conversation/test_init.py | 37 ------------------- .../google_assistant_sdk/test_init.py | 1 - 8 files changed, 1 insertion(+), 101 deletions(-) diff --git a/homeassistant/components/conversation/__init__.py b/homeassistant/components/conversation/__init__.py index 5b82b5dae72..30ecf16bb37 100644 --- a/homeassistant/components/conversation/__init__.py +++ b/homeassistant/components/conversation/__init__.py @@ -195,7 +195,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: hass.http.register_view(ConversationProcessView()) websocket_api.async_register_command(hass, websocket_process) websocket_api.async_register_command(hass, websocket_prepare) - websocket_api.async_register_command(hass, websocket_get_agent_info) websocket_api.async_register_command(hass, websocket_list_agents) websocket_api.async_register_command(hass, websocket_hass_agent_debug) @@ -249,29 +248,6 @@ async def websocket_prepare( connection.send_result(msg["id"]) -@websocket_api.websocket_command( - { - vol.Required("type"): "conversation/agent/info", - vol.Optional("agent_id"): agent_id_validator, - } -) -@websocket_api.async_response -async def websocket_get_agent_info( - hass: HomeAssistant, - connection: websocket_api.ActiveConnection, - msg: dict[str, Any], -) -> None: - """Info about the agent in use.""" - agent = await _get_agent_manager(hass).async_get_agent(msg.get("agent_id")) - - connection.send_result( - msg["id"], - { - "attribution": agent.attribution, - }, - ) - - @websocket_api.websocket_command( { vol.Required("type"): "conversation/agent/list", diff --git a/homeassistant/components/conversation/agent.py b/homeassistant/components/conversation/agent.py index 99b9c9392d8..2eae3631187 100644 --- a/homeassistant/components/conversation/agent.py +++ b/homeassistant/components/conversation/agent.py @@ -3,7 +3,7 @@ from __future__ import annotations from abc import ABC, abstractmethod from dataclasses import dataclass -from typing import Any, Literal, TypedDict +from typing import Any, Literal from homeassistant.core import Context from homeassistant.helpers import intent @@ -35,21 +35,9 @@ class ConversationResult: } -class Attribution(TypedDict): - """Attribution for a conversation agent.""" - - name: str - url: str - - class AbstractConversationAgent(ABC): """Abstract conversation agent.""" - @property - def attribution(self) -> Attribution | None: - """Return the attribution.""" - return None - @property @abstractmethod def supported_languages(self) -> list[str] | Literal["*"]: diff --git a/homeassistant/components/google_assistant_sdk/__init__.py b/homeassistant/components/google_assistant_sdk/__init__.py index db2a8d9512e..4a294489c97 100644 --- a/homeassistant/components/google_assistant_sdk/__init__.py +++ b/homeassistant/components/google_assistant_sdk/__init__.py @@ -128,14 +128,6 @@ class GoogleAssistantConversationAgent(conversation.AbstractConversationAgent): self.session: OAuth2Session | None = None self.language: str | None = None - @property - def attribution(self): - """Return the attribution.""" - return { - "name": "Powered by Google Assistant SDK", - "url": "https://www.home-assistant.io/integrations/google_assistant_sdk/", - } - @property def supported_languages(self) -> list[str]: """Return a list of supported languages.""" diff --git a/homeassistant/components/google_generative_ai_conversation/__init__.py b/homeassistant/components/google_generative_ai_conversation/__init__.py index 3d0fac63420..1154c7132d2 100644 --- a/homeassistant/components/google_generative_ai_conversation/__init__.py +++ b/homeassistant/components/google_generative_ai_conversation/__init__.py @@ -69,14 +69,6 @@ class GoogleGenerativeAIAgent(conversation.AbstractConversationAgent): self.entry = entry self.history: dict[str, list[dict]] = {} - @property - def attribution(self): - """Return the attribution.""" - return { - "name": "Powered by Google Generative AI", - "url": "https://developers.generativeai.google/", - } - @property def supported_languages(self) -> list[str] | Literal["*"]: """Return a list of supported languages.""" diff --git a/homeassistant/components/openai_conversation/__init__.py b/homeassistant/components/openai_conversation/__init__.py index c1b569ce9e1..efa81c7b73c 100644 --- a/homeassistant/components/openai_conversation/__init__.py +++ b/homeassistant/components/openai_conversation/__init__.py @@ -66,11 +66,6 @@ class OpenAIAgent(conversation.AbstractConversationAgent): self.entry = entry self.history: dict[str, list[dict]] = {} - @property - def attribution(self): - """Return the attribution.""" - return {"name": "Powered by OpenAI", "url": "https://www.openai.com"} - @property def supported_languages(self) -> list[str] | Literal["*"]: """Return a list of supported languages.""" diff --git a/tests/components/conversation/__init__.py b/tests/components/conversation/__init__.py index df57c78c9aa..648f8f33811 100644 --- a/tests/components/conversation/__init__.py +++ b/tests/components/conversation/__init__.py @@ -24,11 +24,6 @@ class MockAgent(conversation.AbstractConversationAgent): self.response = "Test response" self._supported_languages = supported_languages - @property - def attribution(self) -> conversation.Attribution | None: - """Return the attribution.""" - return {"name": "Mock assistant", "url": "https://assist.me"} - @property def supported_languages(self) -> list[str]: """Return a list of supported languages.""" diff --git a/tests/components/conversation/test_init.py b/tests/components/conversation/test_init.py index 6ad9beb3362..f89af1dc201 100644 --- a/tests/components/conversation/test_init.py +++ b/tests/components/conversation/test_init.py @@ -1611,43 +1611,6 @@ async def test_get_agent_info( assert agent_info == snapshot -async def test_ws_get_agent_info( - hass: HomeAssistant, - init_components, - mock_agent, - hass_ws_client: WebSocketGenerator, - snapshot: SnapshotAssertion, -) -> None: - """Test get agent info.""" - client = await hass_ws_client(hass) - - await client.send_json_auto_id({"type": "conversation/agent/info"}) - msg = await client.receive_json() - assert msg["success"] - assert msg["result"] == snapshot - - await client.send_json_auto_id( - {"type": "conversation/agent/info", "agent_id": "homeassistant"} - ) - msg = await client.receive_json() - assert msg["success"] - assert msg["result"] == snapshot - - await client.send_json_auto_id( - {"type": "conversation/agent/info", "agent_id": mock_agent.agent_id} - ) - msg = await client.receive_json() - assert msg["success"] - assert msg["result"] == snapshot - - await client.send_json_auto_id( - {"type": "conversation/agent/info", "agent_id": "not_exist"} - ) - msg = await client.receive_json() - assert not msg["success"] - assert msg["error"] == snapshot - - async def test_ws_hass_agent_debug( hass: HomeAssistant, init_components, diff --git a/tests/components/google_assistant_sdk/test_init.py b/tests/components/google_assistant_sdk/test_init.py index 99f264e4a3a..3cb64a9a441 100644 --- a/tests/components/google_assistant_sdk/test_init.py +++ b/tests/components/google_assistant_sdk/test_init.py @@ -326,7 +326,6 @@ async def test_conversation_agent( assert entry.state is ConfigEntryState.LOADED agent = await conversation._get_agent_manager(hass).async_get_agent(entry.entry_id) - assert agent.attribution.keys() == {"name", "url"} assert agent.supported_languages == SUPPORTED_LANGUAGE_CODES text1 = "tell me a joke"