58 lines
2.6 KiB
Python
58 lines
2.6 KiB
Python
import json
|
||
|
||
from review_agent.regulatory_review.services.llm_review import review_condition_fields
|
||
|
||
|
||
def test_review_condition_fields_selects_more_complete_llm_product_name():
|
||
def completion(messages, temperature=0.0):
|
||
return json.dumps(
|
||
{
|
||
"fields": {
|
||
"产品名称": "呼吸道合胞病毒、肺炎支原体核酸检测试剂盒 (荧光PCR法)",
|
||
"型号规格": "24人份/盒",
|
||
}
|
||
},
|
||
ensure_ascii=False,
|
||
)
|
||
|
||
result = review_condition_fields(
|
||
text="产品名称:呼吸道合胞病毒、肺炎支原体核酸检测试剂盒\n(荧光PCR法)\n型号规格:24人份/盒",
|
||
rule_fields={"产品名称": "呼吸道合胞病毒、肺炎支原体核酸检测试剂盒", "型号规格": "24人份/盒"},
|
||
file_context="申请表.txt",
|
||
completion_func=completion,
|
||
)
|
||
|
||
assert result["selected_fields"]["产品名称"] == "呼吸道合胞病毒、肺炎支原体核酸检测试剂盒 (荧光PCR法)"
|
||
assert result["selected_sources"]["产品名称"] == "llm"
|
||
assert result["selected_sources"]["型号规格"] == "rule"
|
||
|
||
|
||
def test_review_condition_fields_falls_back_when_llm_returns_chapter_title():
|
||
def completion(messages, temperature=0.0):
|
||
return json.dumps({"fields": {"产品名称": "第1章 监管信息"}}, ensure_ascii=False)
|
||
|
||
result = review_condition_fields(
|
||
text="产品名称:甲胎蛋白检测试剂盒",
|
||
rule_fields={"产品名称": "甲胎蛋白检测试剂盒"},
|
||
file_context="申请表.txt",
|
||
completion_func=completion,
|
||
)
|
||
|
||
assert result["selected_fields"]["产品名称"] == "甲胎蛋白检测试剂盒"
|
||
assert result["selected_sources"]["产品名称"] == "rule"
|
||
|
||
|
||
def test_review_condition_fields_rejects_garbled_llm_product_name():
|
||
def completion(messages, temperature=0.0):
|
||
return json.dumps({"fields": {"产品名称": "呼吸道合胞病毒、 <20>肺炎支原体核酸检测试剂盒 (荧光PCR法)"}}, ensure_ascii=False)
|
||
|
||
result = review_condition_fields(
|
||
text="呼吸道合胞病毒、肺炎支原体核酸检测试剂盒(荧光PCR法)",
|
||
rule_fields={"产品名称": "呼吸道合胞病毒、肺炎支原体核酸检测试剂盒(荧光PCR法)"},
|
||
file_context="产品列表.txt",
|
||
completion_func=completion,
|
||
)
|
||
|
||
assert result["selected_fields"]["产品名称"] == "呼吸道合胞病毒、肺炎支原体核酸检测试剂盒(荧光PCR法)"
|
||
assert result["selected_sources"]["产品名称"] == "rule"
|