Files
DocsGPT/tests/agents/test_agent_creator.py
Siddhant Rai 3f7de867cc feat: model registry and capabilities for multi-provider support (#2158)
* feat: Implement model registry and capabilities for multi-provider support

- Added ModelRegistry to manage available models and their capabilities.
- Introduced ModelProvider enum for different LLM providers.
- Created ModelCapabilities dataclass to define model features.
- Implemented methods to load models based on API keys and settings.
- Added utility functions for model management in model_utils.py.
- Updated settings.py to include provider-specific API keys.
- Refactored LLM classes (Anthropic, OpenAI, Google, etc.) to utilize new model registry.
- Enhanced utility functions to handle token limits and model validation.
- Improved code structure and logging for better maintainability.

* feat: Add model selection feature with API integration and UI component

* feat: Add model selection and default model functionality in agent management

* test: Update assertions and formatting in stream processing tests

* refactor(llm): Standardize model identifier to model_id

* fix tests

---------

Co-authored-by: Alex <a@tushynski.me>
2025-11-14 13:13:19 +02:00

57 lines
2.5 KiB
Python

import pytest
from application.agents.agent_creator import AgentCreator
from application.agents.classic_agent import ClassicAgent
from application.agents.react_agent import ReActAgent
@pytest.mark.unit
class TestAgentCreator:
def test_create_classic_agent(self, agent_base_params):
agent = AgentCreator.create_agent("classic", **agent_base_params)
assert isinstance(agent, ClassicAgent)
assert agent.endpoint == agent_base_params["endpoint"]
assert agent.llm_name == agent_base_params["llm_name"]
assert agent.model_id == agent_base_params["model_id"]
def test_create_react_agent(self, agent_base_params):
agent = AgentCreator.create_agent("react", **agent_base_params)
assert isinstance(agent, ReActAgent)
assert agent.endpoint == agent_base_params["endpoint"]
assert agent.llm_name == agent_base_params["llm_name"]
def test_create_agent_case_insensitive(self, agent_base_params):
agent_upper = AgentCreator.create_agent("CLASSIC", **agent_base_params)
agent_mixed = AgentCreator.create_agent("ClAsSiC", **agent_base_params)
assert isinstance(agent_upper, ClassicAgent)
assert isinstance(agent_mixed, ClassicAgent)
def test_create_agent_invalid_type(self, agent_base_params):
with pytest.raises(ValueError, match="No agent class found for type"):
AgentCreator.create_agent("invalid_agent_type", **agent_base_params)
def test_agent_registry_contains_expected_agents(self):
assert "classic" in AgentCreator.agents
assert "react" in AgentCreator.agents
assert AgentCreator.agents["classic"] == ClassicAgent
assert AgentCreator.agents["react"] == ReActAgent
def test_create_agent_with_optional_params(self, agent_base_params):
agent_base_params["user_api_key"] = "user_key_123"
agent_base_params["chat_history"] = [{"prompt": "test", "response": "test"}]
agent_base_params["json_schema"] = {"type": "object"}
agent = AgentCreator.create_agent("classic", **agent_base_params)
assert agent.user_api_key == "user_key_123"
assert len(agent.chat_history) == 1
assert agent.json_schema == {"type": "object"}
def test_create_agent_with_attachments(self, agent_base_params):
attachments = [{"name": "file.txt", "content": "test"}]
agent_base_params["attachments"] = attachments
agent = AgentCreator.create_agent("classic", **agent_base_params)
assert agent.attachments == attachments