File size: 2,305 Bytes
915b009 b2929fc ff16d8e b2929fc 599a754 b2929fc 622c8ba b2929fc ff16d8e 622c8ba b2929fc 915b009 599a754 915b009 b2929fc 915b009 b2929fc 915b009 599a754 b2929fc 915b009 b2929fc 915b009 b2929fc 915b009 599a754 b2929fc 622c8ba 915b009 b2929fc ff16d8e |
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 74 75 |
"""Unit tests for Judge Factory and Model Selection.
NOTE: Anthropic is NOT supported (no embeddings API).
See P3_REMOVE_ANTHROPIC_PARTIAL_WIRING.md.
"""
from unittest.mock import patch
import pytest
pytestmark = pytest.mark.unit
from pydantic_ai.models.huggingface import HuggingFaceModel
from pydantic_ai.models.openai import OpenAIChatModel
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.has_openai_key = True
mock_settings.openai_api_key = "sk-test"
mock_settings.openai_model = "gpt-5"
model = get_model()
assert isinstance(model, OpenAIChatModel)
assert model.model_name == "gpt-5"
def test_get_model_byok_openai(mock_settings):
"""Test that BYOK OpenAI key returns OpenAI model."""
mock_settings.has_openai_key = False
mock_settings.openai_model = "gpt-5"
# BYOK takes priority over env vars
model = get_model(api_key="sk-byok-test")
assert isinstance(model, OpenAIChatModel)
def test_get_model_byok_anthropic_raises(mock_settings):
"""Test that BYOK Anthropic key raises NotImplementedError."""
mock_settings.has_openai_key = False
with pytest.raises(NotImplementedError) as exc_info:
get_model(api_key="sk-ant-test")
assert "Anthropic is not supported" in str(exc_info.value)
def test_get_model_huggingface(mock_settings):
"""Test that HuggingFace model is returned when no paid keys."""
mock_settings.has_openai_key = False
mock_settings.hf_token = "hf_test_token"
mock_settings.huggingface_model = "Qwen/Qwen2.5-7B-Instruct"
model = get_model()
assert isinstance(model, HuggingFaceModel)
assert model.model_name == "Qwen/Qwen2.5-7B-Instruct"
def test_get_model_openai_priority(mock_settings):
"""Test OpenAI takes priority when both keys present."""
mock_settings.has_openai_key = True
mock_settings.openai_api_key = "sk-test"
mock_settings.openai_model = "gpt-5"
mock_settings.hf_token = "hf_test_token"
model = get_model()
assert isinstance(model, OpenAIChatModel)
|