Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def _type_to_provider_str(t: type) -> str:
"AzureOpenAIChatCompletionClient": "autogen_ext.models.openai.AzureOpenAIChatCompletionClient",
"openai_chat_completion_client": "autogen_ext.models.openai.OpenAIChatCompletionClient",
"OpenAIChatCompletionClient": "autogen_ext.models.openai.OpenAIChatCompletionClient",
"OllamaChatCompletionClient": "autogen_ext.models.ollama.OllamaChatCompletionClient",
}


Expand Down
21 changes: 21 additions & 0 deletions python/packages/autogen-core/tests/test_component_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,24 @@ def test_component_descriptions() -> None:
assert ComponentWithDocstring("test").dump_component().description == "A component using just docstring."
assert ComponentWithDescription("test").dump_component().description == "Explicit description"
assert ComponentWithDescription("test").dump_component().label == "Custom Component"


def test_ollama_in_well_known_providers() -> None:
"""Test that OllamaChatCompletionClient is included in WELL_KNOWN_PROVIDERS."""
from autogen_core._component_config import WELL_KNOWN_PROVIDERS

# Verify OllamaChatCompletionClient is present
assert "OllamaChatCompletionClient" in WELL_KNOWN_PROVIDERS, "OllamaChatCompletionClient should be in WELL_KNOWN_PROVIDERS"

# Verify correct path
expected_path = "autogen_ext.models.ollama.OllamaChatCompletionClient"
actual_path = WELL_KNOWN_PROVIDERS["OllamaChatCompletionClient"]
assert actual_path == expected_path, f"Expected {expected_path}, got {actual_path}"

# Verify path can be properly parsed (this is what load_component does)
output = actual_path.rsplit(".", maxsplit=1)
assert len(output) == 2, f"Provider path should be splittable: {actual_path}"

module_path, class_name = output
assert module_path == "autogen_ext.models.ollama"
assert class_name == "OllamaChatCompletionClient"
Original file line number Diff line number Diff line change
Expand Up @@ -1313,3 +1313,46 @@ async def _mock_chat(*args: Any, **kwargs: Any) -> ChatResponse:
assert len(create_result.content) > 0
assert isinstance(create_result.content[0], FunctionCall)
assert create_result.content[0].name == add_tool.name


def test_ollama_load_component() -> None:
"""Test that OllamaChatCompletionClient can be loaded via ChatCompletionClient.load_component()."""
from autogen_core.models import ChatCompletionClient

# Test the exact configuration from the issue
config = {
"provider": "OllamaChatCompletionClient",
"config": {
"model": "qwen3",
"host": "http://1.2.3.4:30130",
}
}

# This should not raise an error anymore
client = ChatCompletionClient.load_component(config)

# Verify we got the right type of client
assert isinstance(client, OllamaChatCompletionClient)
assert client._model_name == "qwen3"

# Test that the config was applied correctly
create_args = client.get_create_args()
assert create_args["model"] == "qwen3"


def test_ollama_load_component_via_class() -> None:
"""Test that OllamaChatCompletionClient can be loaded via the class directly."""
config = {
"provider": "OllamaChatCompletionClient",
"config": {
"model": "llama3.2",
"host": "http://localhost:11434",
}
}

# Load via the specific class
client = OllamaChatCompletionClient.load_component(config)

# Verify we got the right type and configuration
assert isinstance(client, OllamaChatCompletionClient)
assert client._model_name == "llama3.2"
Loading