Remove corpus counts from chat chrome

This commit is contained in:
2026-08-10 17:26:58 +07:00
parent 46469468bb
commit 97cb6d16f4
31 changed files with 2192 additions and 424 deletions
+60
View File
@@ -40,6 +40,25 @@ class CitationResponse(BaseModel):
evidence_text: str = ""
class AnswerClaimResponse(BaseModel):
text: str
source_ids: list[str]
class AnswerBlockResponse(BaseModel):
title: str
kind: str
claims: list[AnswerClaimResponse]
class AnswerPlanResponse(BaseModel):
verbosity: str
layout: str
reasoning_mode: str
show_heading: bool
needs_warning: bool
class RagQueryResponse(BaseModel):
trace_id: str
decision: str
@@ -57,6 +76,9 @@ class RagQueryResponse(BaseModel):
# clarify path today; other clarify sources (no_drug, dosing_calc's
# needs_clarify) leave this empty rather than fabricate options.
quick_replies: list[str] = []
blocks: list[AnswerBlockResponse] = []
answer_mode: str = "concise"
answer_plan: AnswerPlanResponse | None = None
def _answer_service(request: Request) -> GroundedAnswerService:
@@ -110,6 +132,32 @@ def _map_citations(items) -> list[CitationResponse]:
]
def _map_blocks(items) -> list[AnswerBlockResponse]:
return [
AnswerBlockResponse(
title=item.title,
kind=item.kind,
claims=[
AnswerClaimResponse(text=claim.text, source_ids=list(claim.source_ids))
for claim in item.claims
],
)
for item in items
]
def _map_plan(item) -> AnswerPlanResponse | None:
if item is None:
return None
return AnswerPlanResponse(
verbosity=item.verbosity,
layout=item.layout,
reasoning_mode=item.reasoning_mode,
show_heading=item.show_heading,
needs_warning=item.needs_warning,
)
@router.post("/query", response_model=RagQueryResponse)
def query_rag(
payload: RagQueryRequest,
@@ -144,6 +192,9 @@ def query_rag(
citations = _map_citations(reply.citations)
generated = reply.generated
quick_replies = list(reply.quick_replies)
blocks = _map_blocks(reply.blocks)
answer_mode = reply.answer_mode
answer_plan = _map_plan(reply.plan)
else:
# No generator configured (ANSWER_PROVIDER=disabled): there is no LLM
# to understand a turn with, so this is retrieval-only, single-turn,
@@ -156,6 +207,9 @@ def query_rag(
citations = []
generated = False
quick_replies = list(grounded.quick_replies)
blocks = []
answer_mode = "concise"
answer_plan = None
else:
decision = grounded.result.decision.value
reason = grounded.result.reason
@@ -164,6 +218,9 @@ def query_rag(
citations = _map_citations(grounded.citations)
generated = grounded.generated
quick_replies = []
blocks = _map_blocks(grounded.blocks)
answer_mode = grounded.answer_mode
answer_plan = _map_plan(grounded.plan)
# Trace persistence is fail-open (F-09): an already-computed, safe answer
# must reach the caller even if Postgres is unreachable. `save()` opens a
@@ -197,4 +254,7 @@ def query_rag(
citations=citations,
generated=generated,
quick_replies=quick_replies,
blocks=blocks,
answer_mode=answer_mode,
answer_plan=answer_plan,
)