examples: Tier 2 claude-agent-service fallback
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
d1a5da1008
commit
e75a635d25
2 changed files with 144 additions and 1 deletions
|
|
@ -9,10 +9,14 @@ import httpx
|
|||
import pytest
|
||||
import respx
|
||||
|
||||
from fire_planner.examples.llm_extract import extract_with_qwen
|
||||
from fire_planner.examples.llm_extract import (
|
||||
extract_with_fallback,
|
||||
extract_with_qwen,
|
||||
)
|
||||
from fire_planner.examples.models import RawPost
|
||||
|
||||
LLAMA_URL = "http://llama-cpp.llama-cpp.svc.cluster.local:8000/v1/chat/completions"
|
||||
CLAUDE_URL = "http://claude-agent-service.claude-agent.svc.cluster.local:8080/v1/chat/completions"
|
||||
|
||||
|
||||
def _post() -> RawPost:
|
||||
|
|
@ -79,3 +83,91 @@ async def test_extract_with_qwen_returns_none_on_http_error() -> None:
|
|||
out = await extract_with_qwen(_post(), llama_url=LLAMA_URL, client=client)
|
||||
|
||||
assert out is None
|
||||
|
||||
|
||||
@respx.mock
|
||||
@pytest.mark.asyncio
|
||||
async def test_fallback_escalates_when_qwen_returns_none() -> None:
|
||||
respx.post(LLAMA_URL).respond(500) # qwen down
|
||||
claude_payload = {
|
||||
"country": "Philippines",
|
||||
"city": "Manila",
|
||||
"confidence": 0.95,
|
||||
}
|
||||
respx.post(CLAUDE_URL).respond(
|
||||
200,
|
||||
json={"choices": [{"message": {"content": json.dumps(claude_payload)}}]},
|
||||
)
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
out = await extract_with_fallback(
|
||||
_post(),
|
||||
llama_url=LLAMA_URL,
|
||||
claude_url=CLAUDE_URL,
|
||||
claude_bearer="t",
|
||||
client=client,
|
||||
)
|
||||
|
||||
assert out is not None
|
||||
assert out.llm_model == "claude-haiku-4-5"
|
||||
assert out.country == "Philippines"
|
||||
|
||||
|
||||
@respx.mock
|
||||
@pytest.mark.asyncio
|
||||
async def test_fallback_escalates_on_low_confidence() -> None:
|
||||
qwen_payload = {"country": None, "confidence": 0.2}
|
||||
respx.post(LLAMA_URL).respond(
|
||||
200,
|
||||
json={"choices": [{"message": {"content": json.dumps(qwen_payload)}}]},
|
||||
)
|
||||
claude_payload = {"country": "Thailand", "city": "Bangkok", "confidence": 0.9}
|
||||
respx.post(CLAUDE_URL).respond(
|
||||
200,
|
||||
json={"choices": [{"message": {"content": json.dumps(claude_payload)}}]},
|
||||
)
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
out = await extract_with_fallback(
|
||||
_post(),
|
||||
llama_url=LLAMA_URL,
|
||||
claude_url=CLAUDE_URL,
|
||||
claude_bearer="t",
|
||||
client=client,
|
||||
confidence_threshold=Decimal("0.5"),
|
||||
)
|
||||
|
||||
assert out is not None
|
||||
assert out.country == "Thailand"
|
||||
assert out.llm_model == "claude-haiku-4-5"
|
||||
|
||||
|
||||
@respx.mock
|
||||
@pytest.mark.asyncio
|
||||
async def test_fallback_keeps_high_confidence_qwen_result() -> None:
|
||||
payload = {
|
||||
"country": "Philippines",
|
||||
"confidence": 0.9,
|
||||
}
|
||||
respx.post(LLAMA_URL).respond(
|
||||
200,
|
||||
json={"choices": [{"message": {"content": json.dumps(payload)}}]},
|
||||
)
|
||||
claude_route = respx.post(CLAUDE_URL).respond(
|
||||
200,
|
||||
json={"choices": [{"message": {"content": "{}"}}]},
|
||||
)
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
out = await extract_with_fallback(
|
||||
_post(),
|
||||
llama_url=LLAMA_URL,
|
||||
claude_url=CLAUDE_URL,
|
||||
claude_bearer="t",
|
||||
client=client,
|
||||
confidence_threshold=Decimal("0.5"),
|
||||
)
|
||||
|
||||
assert out is not None
|
||||
assert out.llm_model == "qwen3-8b"
|
||||
assert claude_route.called is False # high-confidence qwen → claude not hit
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue