LLM-Port mit Schritt-Profilen #47

Merged
torben merged 10 commits from 17-llm-port into main 2026-12-04 21:54:44 +00:00
3 changed files with 50 additions and 1 deletions
Showing only changes of commit f761c27d1a - Show all commits

No files matched your search

+1
View File
@@ -20,6 +20,7 @@ Importe zeigen nach innen: application → ports → domain; adapters → ports,
``` ```
uv sync --locked # Umgebung aus dem Lock uv sync --locked # Umgebung aus dem Lock
uv run pytest uv run pytest
uv run pytest -m live # Live-Test; Key in CHEMENU_ANTHROPIC_API_KEY, nur in der eigenen Shell
uv run ruff check # und: uv run ruff format uv run ruff check # und: uv run ruff format
uv run lint-imports # Schichtregel (Importrichtung) prüfen uv run lint-imports # Schichtregel (Importrichtung) prüfen
uv run pyright uv run pyright
+2 -1
View File
@@ -57,7 +57,8 @@ venv = ".venv"
[tool.pytest.ini_options] [tool.pytest.ini_options]
minversion = "9.0" minversion = "9.0"
testpaths = ["tests"] testpaths = ["tests"]
addopts = ["-ra", "--strict-markers", "--strict-config"] addopts = ["-ra", "--strict-markers", "--strict-config", "-m", "not live"]
markers = ["live: calls a paid provider API; run with -m live"]
xfail_strict = true xfail_strict = true
[tool.importlinter] [tool.importlinter]
+47
View File
@@ -0,0 +1,47 @@
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)