examples: Tier 2 claude-agent-service fallback
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Viktor Barzin 2026-05-28 22:22:24 +00:00
parent d1a5da1008
commit e75a635d25
2 changed files with 144 additions and 1 deletions

View file

@ -128,3 +128,54 @@ def _parse_extracted_json(content: str, record_model: str) -> ExtractedExample |
except ValidationError:
log.warning("LLM JSON failed schema validation: %s", cleaned[:200])
return None
DEFAULT_CONFIDENCE_THRESHOLD = Decimal("0.5")
async def extract_with_claude(
post: RawPost,
claude_url: str,
bearer: str,
client: httpx.AsyncClient,
) -> ExtractedExample | None:
"""Call claude-agent-service. Returns None on any failure."""
return await _call_openai_chat(
url=claude_url,
model_name=CLAUDE_AGENT_MODEL,
post=post,
client=client,
record_model=CLAUDE_AGENT_MODEL,
extra_headers={"Authorization": f"Bearer {bearer}"},
)
async def extract_with_fallback(
post: RawPost,
*,
llama_url: str,
claude_url: str,
claude_bearer: str,
client: httpx.AsyncClient,
confidence_threshold: Decimal = DEFAULT_CONFIDENCE_THRESHOLD,
) -> ExtractedExample | None:
"""Try qwen first; escalate to claude on failure or low confidence.
Returns None only when both backends fail (the orchestrator drops
the post and increments `fire_examples_extract_failed_total`).
"""
primary = await extract_with_qwen(post, llama_url=llama_url, client=client)
if primary is not None and primary.confidence >= confidence_threshold:
return primary
log.info(
"Escalating %s to Tier 2 (primary=%s)",
post.reddit_id,
"none" if primary is None else f"conf={primary.confidence}",
)
secondary = await extract_with_claude(
post,
claude_url=claude_url,
bearer=claude_bearer,
client=client,
)
return secondary or primary