Remove chat rate limit
This commit is contained in:
@@ -15,6 +15,7 @@ from rag.clinical import (
|
||||
RenalContext,
|
||||
)
|
||||
from rag.models import Evidence, SourceRef
|
||||
from rag.sections import SECTION_PHRASES
|
||||
from rag.understanding import (
|
||||
LlmQueryUnderstander,
|
||||
QueryFrame,
|
||||
@@ -173,12 +174,57 @@ def test_named_drug_safety_and_purpose_cues_override_noisy_relation_frames():
|
||||
replace(noisy, drugs=("paracetamol_acetaminophen",)),
|
||||
"Paracetamol có tác dụng gì?",
|
||||
)
|
||||
golden_contraindication = _apply_named_drug_cues(
|
||||
replace(noisy, drugs=("paracetamol_acetaminophen",)),
|
||||
"Chống chỉ định của Paracetamol là gì?",
|
||||
)
|
||||
golden_contraindication_with_omitted_llm_drug = _apply_named_drug_cues(
|
||||
replace(noisy, drugs=()),
|
||||
"Chống chỉ định của Paracetamol là gì?",
|
||||
resolved_turn_drug="paracetamol_acetaminophen",
|
||||
)
|
||||
reverse_contraindication = _apply_named_drug_cues(
|
||||
replace(noisy, drugs=("warfarin",)),
|
||||
"Thuốc nào chống chỉ định ở bệnh nhân đang dùng warfarin?",
|
||||
)
|
||||
|
||||
assert safety.turn_type == "drug_attribute"
|
||||
assert safety.attribute == "chong_chi_dinh"
|
||||
assert safety.needs_clarify is False
|
||||
assert purpose.turn_type == "drug_to_condition"
|
||||
assert purpose.attribute == "chi_dinh"
|
||||
assert golden_contraindication.turn_type == "drug_attribute"
|
||||
assert golden_contraindication.attribute == "chong_chi_dinh"
|
||||
assert golden_contraindication.condition_relation == ConditionRelation.CONTRAINDICATION
|
||||
assert golden_contraindication_with_omitted_llm_drug.turn_type == "drug_attribute"
|
||||
assert golden_contraindication_with_omitted_llm_drug.drugs == (
|
||||
"paracetamol_acetaminophen",
|
||||
)
|
||||
assert reverse_contraindication.turn_type == "condition_relation"
|
||||
|
||||
|
||||
def test_owned_section_phrase_routes_every_monograph_section_without_llm_help():
|
||||
noisy = QueryFrame(
|
||||
turn_type="condition_relation",
|
||||
condition_relation=ConditionRelation.CONTRAINDICATION,
|
||||
needs_clarify=True,
|
||||
clarify_reason="Cần làm rõ",
|
||||
)
|
||||
|
||||
for section_key, phrases in SECTION_PHRASES.items():
|
||||
phrase = phrases[0]
|
||||
corrected = _apply_named_drug_cues(
|
||||
noisy,
|
||||
f"{phrase} của Paracetamol là gì?",
|
||||
resolved_turn_drug="paracetamol_acetaminophen",
|
||||
resolved_section_key=section_key,
|
||||
resolved_section_phrase=phrase,
|
||||
)
|
||||
|
||||
assert corrected.turn_type == "drug_attribute", section_key
|
||||
assert corrected.drugs == ("paracetamol_acetaminophen",), section_key
|
||||
assert corrected.attribute == section_key
|
||||
assert corrected.needs_clarify is False
|
||||
|
||||
|
||||
def test_ambiguous_condition_clarifies_before_retrieval():
|
||||
|
||||
@@ -86,6 +86,30 @@ def test_drug_id_in_exact_underscore_form_resolves():
|
||||
assert frame.unknown_drugs == ()
|
||||
|
||||
|
||||
def test_golden_named_drug_section_overrides_a_misclassified_relation_frame():
|
||||
"""Regression for the production failure observed through the real UI."""
|
||||
understander = LlmQueryUnderstander(_FixedLlm({
|
||||
"turn_type": "condition_relation",
|
||||
"drugs": [],
|
||||
"unknown_drugs": [],
|
||||
"attribute": None,
|
||||
"population": None,
|
||||
"weight_kg": None,
|
||||
"age_text": None,
|
||||
"indication": None,
|
||||
"condition_relation": "contraindication",
|
||||
"needs_clarify": False,
|
||||
"clarify_reason": None,
|
||||
}), CATALOG, RESOLVER)
|
||||
|
||||
frame = understander.understand("Chống chỉ định của Paracetamol là gì?")
|
||||
|
||||
assert frame.turn_type == "drug_attribute"
|
||||
assert frame.drugs == ("paracetamol_acetaminophen",)
|
||||
assert frame.attribute == "chong_chi_dinh"
|
||||
assert frame.needs_clarify is False
|
||||
|
||||
|
||||
def test_exact_candidate_does_not_repeat_the_catalog_wide_fuzzy_scan():
|
||||
resolver = _FakeResolver({"metformin": "metformin"})
|
||||
understander = LlmQueryUnderstander(_FixedLlm({
|
||||
@@ -220,6 +244,11 @@ def test_quick_replies_are_parsed_when_the_model_offers_them():
|
||||
|
||||
|
||||
def test_quick_replies_are_dynamic_but_bounded_before_becoming_ui_chips():
|
||||
# 19 distinct valid entries (after " Người lớn " / "người lớn" dedup
|
||||
# and the non-string 12 are dropped) so the 18-item cap — one per
|
||||
# monograph section, see rag/sections.py SECTION_ORDER — still trims
|
||||
# the last one, not just the old 4-item cap.
|
||||
extra = [f"Lựa chọn {i}" for i in range(6, 20)]
|
||||
understander = LlmQueryUnderstander(_FixedLlm({
|
||||
"turn_type": "dosing_calc", "drugs": ["paracetamol_acetaminophen"],
|
||||
"unknown_drugs": [], "attribute": None, "population": None,
|
||||
@@ -228,14 +257,17 @@ def test_quick_replies_are_dynamic_but_bounded_before_becoming_ui_chips():
|
||||
"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",
|
||||
*extra,
|
||||
],
|
||||
}), 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"
|
||||
assert len(frame.quick_replies) == 18
|
||||
assert frame.quick_replies[:5] == (
|
||||
"Người lớn", "Trẻ em", "Phụ nữ có thai", "Người cao tuổi", "Lựa chọn thứ năm"
|
||||
)
|
||||
assert "Lựa chọn 19" not in frame.quick_replies
|
||||
|
||||
|
||||
def test_string_false_does_not_turn_into_a_clarification():
|
||||
|
||||
Reference in New Issue
Block a user