feat(regulatory): 增加条件字段LLM复核
This commit is contained in:
@@ -117,6 +117,49 @@ def test_detect_regulatory_condition_keeps_wrapped_product_name(settings, tmp_pa
|
||||
assert candidates["model_spec"]["suggested"] == "24人份/盒"
|
||||
|
||||
|
||||
def test_detect_regulatory_condition_uses_llm_review_for_better_product_name(
|
||||
monkeypatch, settings, tmp_path, django_user_model
|
||||
):
|
||||
settings.MEDIA_ROOT = tmp_path
|
||||
user = django_user_model.objects.create_user(username="owner", password="pass")
|
||||
conversation = Conversation.objects.create(user=user, title="会话")
|
||||
summary = FileSummaryBatch.objects.create(
|
||||
conversation=conversation,
|
||||
user=user,
|
||||
batch_no="FS-COND",
|
||||
status=FileSummaryBatch.Status.SUCCESS,
|
||||
product_name="第1章 监管信息",
|
||||
)
|
||||
application = tmp_path / "application.txt"
|
||||
application.write_text(
|
||||
"产品名称:呼吸道合胞病毒、肺炎支原体核酸检测试剂盒\n"
|
||||
"型号规格:24人份/盒\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
FileSummaryItem.objects.create(
|
||||
batch=summary,
|
||||
file_index=1,
|
||||
directory_level="1. 监管信息 / 1.2 申请表",
|
||||
file_name="申请表.txt",
|
||||
file_type="txt",
|
||||
relative_path="1.监管信息/申请表.txt",
|
||||
storage_path=str(application),
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
"review_agent.regulatory_review.services.llm_review.generate_completion",
|
||||
lambda messages, temperature=0.0: json.dumps(
|
||||
{"fields": {"产品名称": "呼吸道合胞病毒、肺炎支原体核酸检测试剂盒 (荧光PCR法)"}},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
)
|
||||
|
||||
candidates = detect_regulatory_condition_candidates(summary)
|
||||
|
||||
assert candidates["product_name"]["suggested"] == "呼吸道合胞病毒、肺炎支原体核酸检测试剂盒 (荧光PCR法)"
|
||||
assert candidates["product_name"]["source"] == "llm"
|
||||
|
||||
|
||||
def test_workflow_pauses_before_rule_scope_until_conditions_confirmed(settings, tmp_path, django_user_model):
|
||||
settings.MEDIA_ROOT = tmp_path
|
||||
user = django_user_model.objects.create_user(username="owner", password="pass")
|
||||
|
||||
42
tests/test_regulatory_llm_review.py
Normal file
42
tests/test_regulatory_llm_review.py
Normal file
@@ -0,0 +1,42 @@
|
||||
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"
|
||||
Reference in New Issue
Block a user