Remove corpus counts from chat chrome
This commit is contained in:
@@ -51,6 +51,7 @@ class _FakeResolver:
|
||||
def __init__(self, known: dict[str, str], suggestions: dict[str, str] | None = None) -> None:
|
||||
self._known = known
|
||||
self._suggestions = suggestions or {}
|
||||
self.suggest_calls = 0
|
||||
|
||||
def resolve(self, query: str) -> _Resolution:
|
||||
low = query.lower()
|
||||
@@ -60,6 +61,7 @@ class _FakeResolver:
|
||||
return _Resolution()
|
||||
|
||||
def suggest(self, query: str, k: int = 3, min_score: float = 0.5):
|
||||
self.suggest_calls += 1
|
||||
low = query.lower()
|
||||
return [
|
||||
(drug_id, 0.9) for needle, drug_id in self._suggestions.items() if needle in low
|
||||
@@ -84,6 +86,21 @@ def test_drug_id_in_exact_underscore_form_resolves():
|
||||
assert frame.unknown_drugs == ()
|
||||
|
||||
|
||||
def test_exact_candidate_does_not_repeat_the_catalog_wide_fuzzy_scan():
|
||||
resolver = _FakeResolver({"metformin": "metformin"})
|
||||
understander = LlmQueryUnderstander(_FixedLlm({
|
||||
"turn_type": "drug_attribute", "drugs": ["metformin"],
|
||||
"unknown_drugs": [], "attribute": "chong_chi_dinh",
|
||||
"population": None, "weight_kg": None, "age_text": None,
|
||||
"indication": None, "needs_clarify": False, "clarify_reason": None,
|
||||
}), CATALOG, resolver)
|
||||
|
||||
frame = understander.understand("chống chỉ định metformin")
|
||||
|
||||
assert frame.drugs == ("metformin",)
|
||||
assert resolver.suggest_calls == 0
|
||||
|
||||
|
||||
def test_drug_id_echoed_with_spaces_instead_of_underscores_still_resolves():
|
||||
"""Reproduces the live 2026-08-06 bug on a genuine multi-turn shape: the
|
||||
drug is named in an earlier turn (in history), the current turn is just
|
||||
@@ -202,6 +219,40 @@ def test_quick_replies_are_parsed_when_the_model_offers_them():
|
||||
assert frame.quick_replies == ("Người lớn", "Trẻ em")
|
||||
|
||||
|
||||
def test_quick_replies_are_dynamic_but_bounded_before_becoming_ui_chips():
|
||||
understander = LlmQueryUnderstander(_FixedLlm({
|
||||
"turn_type": "dosing_calc", "drugs": ["paracetamol_acetaminophen"],
|
||||
"unknown_drugs": [], "attribute": None, "population": None,
|
||||
"weight_kg": None, "age_text": None, "indication": None,
|
||||
"needs_clarify": True, "clarify_reason": "Chọn nhóm phù hợp?",
|
||||
"quick_replies": [
|
||||
" Người lớn ", "người lớn", "Trẻ em", 12,
|
||||
"Phụ nữ có thai", "Người cao tuổi", "Lựa chọn thứ năm",
|
||||
],
|
||||
}), CATALOG, RESOLVER)
|
||||
|
||||
frame = understander.understand("liều paracetamol")
|
||||
|
||||
assert frame.quick_replies == (
|
||||
"Người lớn", "Trẻ em", "Phụ nữ có thai", "Người cao tuổi"
|
||||
)
|
||||
|
||||
|
||||
def test_string_false_does_not_turn_into_a_clarification():
|
||||
understander = LlmQueryUnderstander(_FixedLlm({
|
||||
"turn_type": "drug_attribute", "drugs": ["paracetamol_acetaminophen"],
|
||||
"unknown_drugs": [], "attribute": "chong_chi_dinh", "population": None,
|
||||
"weight_kg": None, "age_text": None, "indication": None,
|
||||
"needs_clarify": "false", "clarify_reason": "Không được hiển thị",
|
||||
"quick_replies": ["Có", "Không"],
|
||||
}), CATALOG, RESOLVER)
|
||||
|
||||
frame = understander.understand("chống chỉ định paracetamol")
|
||||
|
||||
assert frame.needs_clarify is False
|
||||
assert frame.quick_replies == ()
|
||||
|
||||
|
||||
def test_missing_quick_replies_key_defaults_to_empty_not_a_crash():
|
||||
"""The model is asked for `quick_replies` but structured-output providers
|
||||
aren't guaranteed to include every optional key — a clarify without it
|
||||
@@ -240,6 +291,26 @@ def test_route_is_parsed_when_the_model_resolves_it():
|
||||
assert frame.needs_clarify is False
|
||||
|
||||
|
||||
def test_follow_up_exposes_a_first_class_standalone_query():
|
||||
understander = LlmQueryUnderstander(_FixedLlm({
|
||||
"turn_type": "drug_attribute", "drugs": ["metformin"],
|
||||
"unknown_drugs": [], "attribute": "chong_chi_dinh",
|
||||
"population": None, "weight_kg": None, "age_text": None,
|
||||
"indication": None, "route": None,
|
||||
"standalone_query": "Chống chỉ định của metformin",
|
||||
"depends_on_previous_turn": True,
|
||||
"needs_clarify": False, "clarify_reason": None,
|
||||
}), CATALOG, RESOLVER)
|
||||
|
||||
frame = understander.understand(
|
||||
"thế còn chống chỉ định?",
|
||||
history=("Người dùng: Metformin dùng để làm gì?",),
|
||||
)
|
||||
|
||||
assert frame.standalone_query == "Chống chỉ định của metformin"
|
||||
assert frame.depends_on_previous_turn is True
|
||||
|
||||
|
||||
def test_missing_route_key_defaults_to_none_not_a_crash():
|
||||
understander = LlmQueryUnderstander(_FixedLlm({
|
||||
"turn_type": "dosing_calc", "drugs": [],
|
||||
|
||||
Reference in New Issue
Block a user