File size: 2,558 Bytes
b2929fc
 
 
 
 
 
 
 
ce644a9
b2929fc
ce644a9
 
 
 
 
 
 
 
b2929fc
 
 
 
 
 
 
 
 
 
 
 
 
 
58ff8fb
b2929fc
 
 
58ff8fb
b2929fc
 
 
 
 
 
58ff8fb
b2929fc
 
 
58ff8fb
b2929fc
 
ce644a9
b2929fc
 
 
 
 
 
 
 
 
 
 
ce644a9
b2929fc
cd46aca
b2929fc
cd46aca
ce644a9
b2929fc
 
cd46aca
ce644a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Unit tests for Judge Factory and Model Selection."""

from unittest.mock import patch

import pytest

pytestmark = pytest.mark.unit
from pydantic_ai.models.anthropic import AnthropicModel
from pydantic_ai.models.openai import OpenAIModel

# Try to import HuggingFace support (may not be available in all pydantic-ai versions)
try:
    from pydantic_ai.models.huggingface import HuggingFaceModel

    _HUGGINGFACE_AVAILABLE = True
except ImportError:
    HuggingFaceModel = None  # type: ignore[assignment, misc]
    _HUGGINGFACE_AVAILABLE = False

from src.agent_factory.judges import get_model


@pytest.fixture
def mock_settings():
    with patch("src.agent_factory.judges.settings", autospec=True) as mock_settings:
        yield mock_settings


def test_get_model_openai(mock_settings):
    """Test that OpenAI model is returned when provider is openai."""
    mock_settings.llm_provider = "openai"
    mock_settings.openai_api_key = "sk-test"
    mock_settings.openai_model = "gpt-5.1"

    model = get_model()
    assert isinstance(model, OpenAIModel)
    assert model.model_name == "gpt-5.1"


def test_get_model_anthropic(mock_settings):
    """Test that Anthropic model is returned when provider is anthropic."""
    mock_settings.llm_provider = "anthropic"
    mock_settings.anthropic_api_key = "sk-ant-test"
    mock_settings.anthropic_model = "claude-sonnet-4-5-20250929"

    model = get_model()
    assert isinstance(model, AnthropicModel)
    assert model.model_name == "claude-sonnet-4-5-20250929"


@pytest.mark.skipif(not _HUGGINGFACE_AVAILABLE, reason="HuggingFace models not available")
def test_get_model_huggingface(mock_settings):
    """Test that HuggingFace model is returned when provider is huggingface."""
    mock_settings.llm_provider = "huggingface"
    mock_settings.hf_token = "hf_test_token"
    mock_settings.huggingface_model = "meta-llama/Llama-3.1-70B-Instruct"

    model = get_model()
    assert isinstance(model, HuggingFaceModel)
    assert model.model_name == "meta-llama/Llama-3.1-70B-Instruct"


@pytest.mark.skipif(not _HUGGINGFACE_AVAILABLE, reason="HuggingFace models not available")
def test_get_model_default_fallback(mock_settings):
    """Test fallback to HuggingFace if provider is unknown."""
    mock_settings.llm_provider = "unknown_provider"
    mock_settings.hf_token = "hf_test_token"
    mock_settings.huggingface_model = "Qwen/Qwen3-Next-80B-A3B-Thinking"

    model = get_model()
    assert isinstance(model, HuggingFaceModel)
    assert model.model_name == "Qwen/Qwen3-Next-80B-A3B-Thinking"