Soften the tone of the docs and comments written today
This commit is contained in:
@@ -259,12 +259,27 @@ class RagAgent:
|
||||
if frame.population in {"tre_em", "tre_so_sinh"} and (
|
||||
frame.age_text is None or frame.weight_kg is None
|
||||
):
|
||||
# Both fields stay required. The formulary branches pediatric
|
||||
# dosing on BOTH — paracetamol prints an age band ("Trẻ em
|
||||
# 4-6 tuổi: 240 mg") *and* a weight rule ("10-50 kg: 15
|
||||
# mg/kg") — so answering with only one of them would mean
|
||||
# picking a regimen the source does not let us pick.
|
||||
#
|
||||
# What changed on 2026-08-11 is the *question*, not the gate.
|
||||
# The fallback used to ask for age and weight every time,
|
||||
# including for whichever field the user had already given
|
||||
# (reproduced 5/5 live: "Bé 18 ký ...", "Bé nặng 18 kg ...",
|
||||
# "Trẻ 5 tuổi ..." all received the same sentence). The
|
||||
# effect was most visible when understanding.py did well: a
|
||||
# frame that parsed the weight and set needs_clarify=false
|
||||
# reaches this fallback, so a clearer question from the user
|
||||
# produced a more redundant question back.
|
||||
return AgentReply(
|
||||
"clarify", "missing_pediatric_age_or_weight",
|
||||
clarification=(
|
||||
frame.clarify_reason
|
||||
if frame.needs_clarify and frame.clarify_reason
|
||||
else "Bé bao nhiêu tuổi và cân nặng bao nhiêu kg?"
|
||||
else _pediatric_clarify_question(frame)
|
||||
),
|
||||
drugs=frame.drugs, turn_type=tt,
|
||||
quick_replies=(
|
||||
@@ -498,6 +513,32 @@ def _display_name(drug_id: str) -> str:
|
||||
return drug_id.replace("_", " ").title()
|
||||
|
||||
|
||||
def _pediatric_clarify_question(frame: QueryFrame) -> str:
|
||||
"""Ask for the pediatric field that is actually missing.
|
||||
|
||||
The caller still requires both age and weight; this only stops the
|
||||
question from asking for something the user already supplied in the very
|
||||
same sentence, which reads as not having been listened to and invites
|
||||
them to repeat themselves into the clarify-loop breaker.
|
||||
|
||||
When a field IS known it is echoed back, so the user can see the value
|
||||
was received and correct it if the parse was wrong (e.g. a colloquial
|
||||
"18 ký" read as 18 kg).
|
||||
"""
|
||||
has_age = frame.age_text is not None
|
||||
has_weight = frame.weight_kg is not None
|
||||
if has_age and not has_weight:
|
||||
return f"Bé {frame.age_text} nặng bao nhiêu kg?"
|
||||
if has_weight and not has_age:
|
||||
return f"Bé nặng {_format_kg(frame.weight_kg)} kg, vậy bé bao nhiêu tuổi?"
|
||||
return "Bé bao nhiêu tuổi và cân nặng bao nhiêu kg?"
|
||||
|
||||
|
||||
def _format_kg(weight_kg: float) -> str:
|
||||
"""Render a weight without a trailing '.0' on whole kilograms."""
|
||||
return f"{weight_kg:g}"
|
||||
|
||||
|
||||
def _is_section_overview(turn: str, frame: QueryFrame) -> bool:
|
||||
"""Separate a handbook survey from a patient-specific decision.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user