调整提示词、简化代码

This commit is contained in:
2025-09-25 16:23:13 +08:00
parent 640e02f89e
commit 2b13fdab99
5 changed files with 235 additions and 476 deletions
+17 -21
View File
@@ -17,21 +17,18 @@ from typing import List, Tuple, Dict, Any, Optional
import re
import jieba
import time
import threading
from .PromptTemplates import (classification_prompt, query_rewrite_prompt_pro,
extract_nouns_prompt, classification_info,
slot_filling_prompt, step_back_prompt,
hyde_prompt)
slot_filling_prompt, step_back_prompt)
from .DataModels import (
Classification, QueryRewrite, Term, TermList,
SoftwareFunctionSlots, SoftwareTroubleShootingSlots, ProfessionalConsultingSlots,
DataProblemSlots, FileExtensionConsultingSlots, SoftwareLockSlots,
InstallationDownloadSlots, ProblemDiagnosisSlots, OtherSlots, IntentAndSlotResult,
StepBackPrompt, HypotheticalDocument
InstallationDownloadSlots, ProblemDiagnosisSlots, OtherSlots,
StepBackPrompt
)
from .ProfessionalNounVector import ProfessionalNounRetriever, AsyncProfessionalNounRetriever
from rag2_0.tool.ModelTool import OpenAiLLM
class AsyncIntentRecognizer:
@@ -344,22 +341,20 @@ class AsyncIntentRecognizer:
"""
start_time = time.time() # 记录开始时间
prompt=f"""
当前提问内容:
<query>{query}</query>
对话上下文:
<chat_history>
{json.dumps(chat_history, ensure_ascii=False)}
</chat_history>
prompt=f"""当前提问内容:
<query>{query}</query>
对话上下文:
<chat_history>
{json.dumps(chat_history, ensure_ascii=False)}
</chat_history>
1、请从当前提问内容中提取电力造价行中定额编码、定额名称、清单编码、清单名称
2、请勿随机编造,如果没有提取到内容返回空的JSON
3、返回结果为json格式,必须严格以纯JSON格式输出
{{
"dinge_info_list":{{"dinge_code_list":["xxxx","xxxx"], "dinge_name_list":["xxxx","xxxx"]}},
"qingdan_info":{{"qingdan_code_list":["xxxx","xxxx"], "qingdan_name_list":["xxxx","xxxx"]}}
}}
"""
1、请从当前提问内容中提取电力造价行中定额编码、定额名称、清单编码、清单名称
2、请勿随机编造,如果没有提取到内容返回空的JSON
3、返回结果为json格式,必须严格以纯JSON格式输出
{{
"dinge_info_list":{{"dinge_code_list":["xxxx","xxxx"], "dinge_name_list":["xxxx","xxxx"]}},
"qingdan_info":{{"qingdan_code_list":["xxxx","xxxx"], "qingdan_name_list":["xxxx","xxxx"]}}
}}"""
try:
# response = await self._llm.ainvoke(prompt, response_format={"type": "json_object"}, extra_body={"enable_thinking": False})
@@ -489,6 +484,7 @@ class AsyncIntentRecognizer:
# 特殊处理 锁相关咨询
if classification.vertical_classification == "安装下载注册" and classification.sub_classification == "软件锁类":
process_lock_start_time = time.time()
# 特殊处理提问只有锁号的问题,手动将问题改写为特定格式
rewrite.rewrite = self._process_lock_related_query(rewrite.rewrite)
process_lock_end_time = time.time()
process_lock_time = process_lock_end_time - process_lock_start_time