Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
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" # type: ignore[reportPrivateUsage]

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


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" # type: ignore[reportPrivateUsage]
Loading