Plain pytest deselects it; -m live runs it and skips without a key. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
import os
|
|
|
|
import pytest
|
|
from pydantic import BaseModel
|
|
|
|
from chemenu.adapters.llm.config import LlmConfig
|
|
from chemenu.adapters.llm.factory import build_llm
|
|
from chemenu.domain.step_profile import StepProfile
|
|
from chemenu.ports.llm import LlmRequest
|
|
|
|
_KEY_ENV = "CHEMENU_ANTHROPIC_API_KEY"
|
|
_MODEL = "claude-haiku-5-5"
|
|
|
|
|
|
class _Answer(BaseModel):
|
|
answer: int
|
|
|
|
|
|
@pytest.mark.live
|
|
def test_live_anthropic_call() -> None:
|
|
if not os.environ.get(_KEY_ENV):
|
|
pytest.skip(f"{_KEY_ENV} not set; the live test calls a paid API")
|
|
config = LlmConfig.model_validate(
|
|
{
|
|
"providers": {"anthropic": {"kind": "anthropic", "api_key_env": _KEY_ENV}},
|
|
"profiles": {
|
|
"classify": {
|
|
"provider": "anthropic",
|
|
"model": _MODEL,
|
|
"effort": "low",
|
|
"max_tokens": 2000,
|
|
"timeout_seconds": 120,
|
|
}
|
|
},
|
|
}
|
|
)
|
|
port = build_llm(config, os.environ)
|
|
request = LlmRequest(
|
|
step="live-check",
|
|
profile=StepProfile.CLASSIFY,
|
|
prompt="Wie viel ist 2+3?",
|
|
output_model=_Answer,
|
|
)
|
|
response = port.complete(request)
|
|
assert response.model == _MODEL
|
|
assert response.usage.input_tokens > 0
|
|
_Answer.model_validate_json(response.text, strict=True)
|