From a8a20c9aa86fc103f0ace947dff219f8f8cbaea8 Mon Sep 17 00:00:00 2001 From: Bicheng Wang Date: Thu, 8 Oct 2026 12:44:42 -0700 Subject: [PATCH] Python: Add service_url to OllamaChatClient Report the Ollama host as server.address in chat telemetry instead of the base class default of Unknown, matching OllamaEmbeddingClient and the other provider chat clients. --- .../ollama/agent_framework_ollama/_chat_client.py | 9 +++++++++ python/packages/ollama/tests/test_ollama_chat_client.py | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/python/packages/ollama/agent_framework_ollama/_chat_client.py b/python/packages/ollama/agent_framework_ollama/_chat_client.py index 7b27a4c660f..e4c2da395df 100644 --- a/python/packages/ollama/agent_framework_ollama/_chat_client.py +++ b/python/packages/ollama/agent_framework_ollama/_chat_client.py @@ -348,6 +348,15 @@ def __init__( ) self.middleware = list(self.chat_middleware) + @override + def service_url(self) -> str: + """Get the URL of the Ollama service. + + Returns: + The Ollama server URL, used for the ``server.address`` telemetry attribute. + """ + return self.host + @override def _inner_get_response( self, diff --git a/python/packages/ollama/tests/test_ollama_chat_client.py b/python/packages/ollama/tests/test_ollama_chat_client.py index 8c5e21172f2..84042eecd4f 100644 --- a/python/packages/ollama/tests/test_ollama_chat_client.py +++ b/python/packages/ollama/tests/test_ollama_chat_client.py @@ -188,6 +188,12 @@ def test_init_client(ollama_unit_test_env: dict[str, str]) -> None: assert isinstance(ollama_chat_client, BaseChatClient) +def test_service_url(ollama_unit_test_env: dict[str, str]) -> None: + ollama_chat_client = OllamaChatClient(host="http://ollama.example:9999") + + assert ollama_chat_client.service_url().rstrip("/") == "http://ollama.example:9999" + + @pytest.mark.parametrize("exclude_list", [["OLLAMA_MODEL"]], indirect=True) def test_with_invalid_settings(ollama_unit_test_env: dict[str, str]) -> None: with pytest.raises(SettingNotFoundError, match="Required setting 'model'"):