Remove corpus counts from chat chrome
This commit is contained in:
@@ -124,6 +124,24 @@ def test_no_drug_named_asks_which_one():
|
||||
assert reply.reason == "no_drug"
|
||||
|
||||
|
||||
def test_drug_attribute_without_an_attribute_does_not_fall_into_overview_retrieval():
|
||||
retrieval = _FixedRetrieval({})
|
||||
answers = GroundedAnswerService(routing=None)
|
||||
agent = RagAgent(
|
||||
_FixedUnderstander(QueryFrame(
|
||||
turn_type="drug_attribute", drugs=("paracetamol_acetaminophen",)
|
||||
)),
|
||||
retrieval,
|
||||
answers,
|
||||
)
|
||||
|
||||
reply = agent.handle("paracetamol thì sao?")
|
||||
|
||||
assert reply.decision == "clarify"
|
||||
assert reply.reason == "missing_attribute"
|
||||
assert retrieval.calls == []
|
||||
|
||||
|
||||
def test_needs_clarify_frame_is_surfaced_directly():
|
||||
agent = _agent(QueryFrame(
|
||||
turn_type="dosing_calc", drugs=("paracetamol",),
|
||||
@@ -137,6 +155,22 @@ def test_needs_clarify_frame_is_surfaced_directly():
|
||||
assert reply.quick_replies == ()
|
||||
|
||||
|
||||
def test_understanding_provider_failure_is_an_abstain_not_a_fake_clarification():
|
||||
agent = _agent(QueryFrame(
|
||||
turn_type="out_of_scope",
|
||||
needs_clarify=True,
|
||||
clarify_reason="Dịch vụ đang gặp sự cố tạm thời.",
|
||||
system_error="understanding_provider_unavailable",
|
||||
))
|
||||
|
||||
reply = agent.handle("liều paracetamol")
|
||||
|
||||
assert reply.decision == "abstain"
|
||||
assert reply.reason == "understanding_provider_unavailable"
|
||||
assert reply.answer == "Dịch vụ đang gặp sự cố tạm thời."
|
||||
assert reply.clarification is None
|
||||
|
||||
|
||||
def test_needs_clarify_frame_carries_quick_replies_through():
|
||||
"""This is the path real traffic actually hits (checked live): the
|
||||
understanding LLM call itself sets needs_clarify/clarify_reason before
|
||||
@@ -153,6 +187,167 @@ def test_needs_clarify_frame_carries_quick_replies_through():
|
||||
assert reply.quick_replies == ("Người lớn", "Trẻ em")
|
||||
|
||||
|
||||
def test_dosing_without_route_asks_only_when_evidence_is_ambiguous():
|
||||
result = RetrievalResult(
|
||||
EvidenceDecision.ANSWERABLE,
|
||||
"grounded_evidence_available",
|
||||
(
|
||||
_evidence("Đường uống, người lớn: 500 mg mỗi lần."),
|
||||
_evidence("Đặt trực tràng, người lớn: 500 mg mỗi lần."),
|
||||
),
|
||||
resolved_drug_id="paracetamol_acetaminophen",
|
||||
)
|
||||
|
||||
class _Generator:
|
||||
def generate(self, system, user, schema):
|
||||
return (
|
||||
'{"claims": [], "evidence_sufficient": false, '
|
||||
'"clarifying_question": "Anh/chị muốn dùng đường nào?", '
|
||||
'"quick_replies": ["Uống", "Đặt trực tràng"]}'
|
||||
)
|
||||
|
||||
retrieval = _FixedRetrieval({"paracetamol_acetaminophen": result})
|
||||
answers = GroundedAnswerService(routing=None, generator=_Generator())
|
||||
agent = RagAgent(
|
||||
_FixedUnderstander(QueryFrame(
|
||||
turn_type="dosing_calc",
|
||||
drugs=("paracetamol_acetaminophen",),
|
||||
population="nguoi_lon",
|
||||
)),
|
||||
retrieval,
|
||||
answers,
|
||||
)
|
||||
|
||||
reply = agent.handle("Người lớn", conversation_id="dose-route")
|
||||
|
||||
assert reply.decision == "clarify"
|
||||
assert reply.reason == "needs_more_info"
|
||||
assert reply.quick_replies == ("Uống", "Đặt trực tràng")
|
||||
assert len(retrieval.calls) == 1
|
||||
remembered = agent._last_frame["dose-route"]
|
||||
assert remembered.needs_clarify is True
|
||||
assert remembered.population == "nguoi_lon"
|
||||
assert remembered.clarify_reason == reply.clarification
|
||||
|
||||
|
||||
def test_dosing_without_route_answers_directly_when_evidence_has_one_route():
|
||||
result = RetrievalResult(
|
||||
EvidenceDecision.ANSWERABLE,
|
||||
"grounded_evidence_available",
|
||||
(_evidence("Đường uống, người lớn: 500 mg mỗi lần."),),
|
||||
resolved_drug_id="paracetamol_acetaminophen",
|
||||
)
|
||||
|
||||
class _Generator:
|
||||
def generate(self, system, user, schema):
|
||||
if "entailed" in schema.get("properties", {}):
|
||||
return '{"entailed": true, "unsupported": []}'
|
||||
return (
|
||||
'{"claims": [{"text": "Đường uống, người lớn: 500 mg mỗi lần.", '
|
||||
'"citations": [1]}], "evidence_sufficient": true, '
|
||||
'"clarifying_question": null, "quick_replies": []}'
|
||||
)
|
||||
|
||||
retrieval = _FixedRetrieval({"paracetamol_acetaminophen": result})
|
||||
answers = GroundedAnswerService(routing=None, generator=_Generator())
|
||||
agent = RagAgent(
|
||||
_FixedUnderstander(QueryFrame(
|
||||
turn_type="dosing_calc",
|
||||
drugs=("paracetamol_acetaminophen",),
|
||||
population="nguoi_lon",
|
||||
)),
|
||||
retrieval,
|
||||
answers,
|
||||
)
|
||||
|
||||
reply = agent.handle("Liều Paracetamol cho người lớn")
|
||||
|
||||
assert reply.decision == "answerable"
|
||||
assert reply.quick_replies == ()
|
||||
assert "500 mg" in reply.answer
|
||||
assert len(retrieval.calls) == 1
|
||||
|
||||
|
||||
def test_general_dosage_section_survey_does_not_force_population_chip():
|
||||
result = RetrievalResult(
|
||||
EvidenceDecision.ANSWERABLE,
|
||||
"grounded_evidence_available",
|
||||
(_evidence("Người lớn: uống 10 mg. Trẻ em: liều theo cân nặng."),),
|
||||
resolved_drug_id="example",
|
||||
)
|
||||
retrieval = _FixedRetrieval({"example": result})
|
||||
agent = RagAgent(
|
||||
_FixedUnderstander(QueryFrame(
|
||||
turn_type="dosing_calc",
|
||||
drugs=("example",),
|
||||
needs_clarify=True,
|
||||
clarify_reason="Người lớn hay trẻ em?",
|
||||
)),
|
||||
retrieval,
|
||||
GroundedAnswerService(routing=None),
|
||||
)
|
||||
|
||||
reply = agent.handle(
|
||||
"Dược thư hướng dẫn dùng Example thế nào: đường dùng và các liều nếu có?"
|
||||
)
|
||||
|
||||
assert reply.decision == "answerable"
|
||||
assert reply.quick_replies == ()
|
||||
assert "tra cứu tổng quan toàn mục" in retrieval.calls[0][2]
|
||||
|
||||
|
||||
def test_clear_precaution_section_survey_overrides_model_overclarification():
|
||||
result = RetrievalResult(
|
||||
EvidenceDecision.ANSWERABLE,
|
||||
"grounded_evidence_available",
|
||||
(_evidence("Theo dõi chức năng thận và điện giải."),),
|
||||
resolved_drug_id="example",
|
||||
)
|
||||
agent = _agent(
|
||||
QueryFrame(
|
||||
turn_type="drug_attribute",
|
||||
drugs=("example",),
|
||||
attribute="than_trong",
|
||||
needs_clarify=True,
|
||||
clarify_reason="Muốn hỏi thận trọng hay chống chỉ định?",
|
||||
),
|
||||
{"example": result},
|
||||
)
|
||||
|
||||
reply = agent.handle("Những tình huống nào cần thận trọng khi dùng Example?")
|
||||
|
||||
assert reply.decision == "answerable"
|
||||
assert reply.quick_replies == ()
|
||||
|
||||
|
||||
def test_complete_adult_dosing_core_ignores_an_irrelevant_weight_reask():
|
||||
result = RetrievalResult(
|
||||
EvidenceDecision.ANSWERABLE, "grounded_evidence_available",
|
||||
(_evidence("Đường uống, người lớn: 500 mg mỗi lần."),),
|
||||
resolved_drug_id="paracetamol_acetaminophen",
|
||||
)
|
||||
retrieval = _FixedRetrieval({"paracetamol_acetaminophen": result})
|
||||
answers = GroundedAnswerService(routing=None)
|
||||
agent = RagAgent(
|
||||
_FixedUnderstander(QueryFrame(
|
||||
turn_type="dosing_calc",
|
||||
drugs=("paracetamol_acetaminophen",),
|
||||
population="nguoi_lon",
|
||||
route="uong",
|
||||
needs_clarify=True,
|
||||
clarify_reason="Cân nặng của người lớn là bao nhiêu kg?",
|
||||
)),
|
||||
retrieval,
|
||||
answers,
|
||||
)
|
||||
|
||||
reply = agent.handle("Uống")
|
||||
|
||||
assert reply.decision == "answerable"
|
||||
assert len(retrieval.calls) == 1
|
||||
assert retrieval.calls[0][1] == "lieu_luong_va_cach_dung"
|
||||
|
||||
|
||||
def test_single_drug_attribute_retrieves_and_answers():
|
||||
result = RetrievalResult(
|
||||
EvidenceDecision.ANSWERABLE, "grounded_evidence_available",
|
||||
@@ -490,7 +685,10 @@ def test_a_generous_budget_does_not_change_normal_behaviour():
|
||||
return '{"sufficient": true, "clarifying_question": null, "quick_replies": []}'
|
||||
if "entailed" in schema.get("properties", {}):
|
||||
return '{"entailed": true, "unsupported": []}'
|
||||
return '{"answer": "Liều 500 mg [1].", "evidence_sufficient": true, "clarifying_question": null}'
|
||||
return (
|
||||
'{"claims": [{"text": "Liều 500 mg", "citations": [1]}], '
|
||||
'"evidence_sufficient": true, "clarifying_question": null}'
|
||||
)
|
||||
|
||||
answers = GroundedAnswerService(routing=None, generator=_Generator())
|
||||
agent = RagAgent(
|
||||
@@ -500,7 +698,8 @@ def test_a_generous_budget_does_not_change_normal_behaviour():
|
||||
reply = agent.handle("liều metformin")
|
||||
|
||||
assert reply.decision == "answerable"
|
||||
assert reply.answer == "Liều 500 mg [1]."
|
||||
assert reply.answer == "Liều 500 mg"
|
||||
assert reply.blocks[0].claims[0].source_ids
|
||||
|
||||
|
||||
# --- durable conversation history (ADR 0008's named gap): an optional
|
||||
|
||||
Reference in New Issue
Block a user