Fix ai-service Dockerfile: bake in drug_entities.json, override its path

This commit is contained in:
2026-08-10 10:35:13 +07:00
parent a4b8e1c4db
commit 60b4397032
51 changed files with 4302 additions and 2087 deletions
+22
View File
@@ -35,6 +35,9 @@ class CitationResponse(BaseModel):
bbox: tuple[float, float, float, float] | None = None
source_crop: str | None = None
attachment: str | None = None
# The exact retrieved chunk text this citation stands for — lets the UI
# show precisely what was retrieved, not a client-side guess at it.
evidence_text: str = ""
class RagQueryResponse(BaseModel):
@@ -44,6 +47,16 @@ class RagQueryResponse(BaseModel):
answer: str | None
resolved_drug_id: str | None
citations: list[CitationResponse]
# Whether `answer` is an LLM paraphrase (verified by grounding +
# entailment) or a verbatim extractive quote of the retrieved source —
# the UI shows these differently so a clinician knows which they're
# reading.
generated: bool = False
# Short suggested replies for a `decision == "clarify"` turn (e.g.
# ["Người lớn", "Trẻ em"]) — only populated by the sufficiency-check
# clarify path today; other clarify sources (no_drug, dosing_calc's
# needs_clarify) leave this empty rather than fabricate options.
quick_replies: list[str] = []
def _answer_service(request: Request) -> GroundedAnswerService:
@@ -91,6 +104,7 @@ def _map_citations(items) -> list[CitationResponse]:
bbox=item.bbox,
source_crop=item.source_crop,
attachment=item.attachment,
evidence_text=item.evidence_text,
)
for item in items
]
@@ -128,6 +142,8 @@ def query_rag(
answer = reply.clarification if reply.clarification is not None else reply.answer
resolved_drug_id = ", ".join(reply.drugs) if reply.drugs else None
citations = _map_citations(reply.citations)
generated = reply.generated
quick_replies = list(reply.quick_replies)
else:
# No generator configured (ANSWER_PROVIDER=disabled): there is no LLM
# to understand a turn with, so this is retrieval-only, single-turn,
@@ -138,12 +154,16 @@ def query_rag(
answer = grounded.clarification
resolved_drug_id = grounded.result.resolved_drug_id
citations = []
generated = False
quick_replies = list(grounded.quick_replies)
else:
decision = grounded.result.decision.value
reason = grounded.result.reason
answer = grounded.answer
resolved_drug_id = grounded.result.resolved_drug_id
citations = _map_citations(grounded.citations)
generated = grounded.generated
quick_replies = []
# Trace persistence is fail-open (F-09): an already-computed, safe answer
# must reach the caller even if Postgres is unreachable. `save()` opens a
@@ -175,4 +195,6 @@ def query_rag(
answer=answer,
resolved_drug_id=resolved_drug_id,
citations=citations,
generated=generated,
quick_replies=quick_replies,
)