feat(classifier): optional GigaChat-2-Lite hybrid tier classify
CI / build-gateway (push) Successful in 3s
CI / sync-config (push) Successful in 1s

LLM classify via LiteLLM gigachat-classifier when heuristic confidence
is low. CLASSIFIER_MODE=heuristic|hybrid|llm. Metrics classifier_source.
This commit is contained in:
2026-08-07 22:21:27 +03:00
parent 83d516afa1
commit 6fd2f0e689
11 changed files with 213 additions and 7 deletions
+8 -3
View File
@@ -15,7 +15,7 @@ import httpx
from fastapi import FastAPI, Header, HTTPException, Request, Response
from fastapi.responses import JSONResponse, StreamingResponse
from metrics import CLASSIFY, DURATION, ESCALATIONS, REQUESTS, metrics_payload
from metrics import CLASSIFY, CLASSIFY_LLM, DURATION, ESCALATIONS, REQUESTS, metrics_payload
from orchestrator import Orchestrator, SessionStore, Tier
from rules_loader import reload_configs
@@ -104,6 +104,7 @@ def _router_meta(decision, *, requested: str) -> dict[str, Any]:
"confidence": round(decision.confidence, 3),
"requested_model": requested,
"delegated_internal": decision.delegated_internal,
"classifier_source": decision.classifier_source,
}
@@ -150,7 +151,7 @@ async def classify_debug(
body = await request.json()
messages = body.get("messages") or []
text = _extract_text(messages)
decision = orchestrator.resolve(
decision = await orchestrator.resolve(
messages,
quality_mode=_quality_mode(x_ai_quality, body),
session_id=_session_id(body),
@@ -159,6 +160,8 @@ async def classify_debug(
token_estimate=_estimate_tokens(text),
)
CLASSIFY.labels(tier=decision.tier.value).inc()
if decision.classifier_source == "gigachat":
CLASSIFY_LLM.labels(tier=decision.tier.value, status="ok").inc()
return {
"tier": decision.tier.value,
"lane": decision.lane,
@@ -243,7 +246,7 @@ async def chat_completions(
requested_model = body.get("model", DEFAULT_MODEL)
if requested_model in ("smart-router", "auto", ""):
decision = orchestrator.resolve(
decision = await orchestrator.resolve(
messages,
quality_mode=_quality_mode(x_ai_quality, body),
session_id=session_id,
@@ -251,6 +254,8 @@ async def chat_completions(
has_image=has_image,
token_estimate=_estimate_tokens(text),
)
if decision.classifier_source == "gigachat":
CLASSIFY_LLM.labels(tier=decision.tier.value, status="ok").inc()
target_model = decision.model
meta = _router_meta(decision, requested=requested_model)
else: