更新.gitignore以忽略查询日志文件,优化意图识别逻辑,新增锁相关咨询处理方法,并调整后退提示的返回结构以支持固定话术类问题。
This commit is contained in:
@@ -378,6 +378,18 @@ class AsyncIntentRecognizer:
|
||||
|
||||
return bool(matched_suffixes), matched_suffixes
|
||||
|
||||
def _process_lock_related_query(self, query: str) -> str:
|
||||
"""
|
||||
特殊处理锁相关咨询
|
||||
"""
|
||||
pattern = r'(?<!\d)(?:8116(?:\s*\d){8}|\d{2}\s*-\s*\d{6})(?!\d)'
|
||||
matches = re.findall(pattern, query)
|
||||
if not matches:
|
||||
return query
|
||||
lock_number = "、".join(matches)
|
||||
return f"通过博微软件助手查询软件锁信息,锁注册号为{lock_number}"
|
||||
|
||||
|
||||
async def process_query_async(self, query: str, conversation_context: str = "",
|
||||
chat_history: List[Dict[str, str]] = None,
|
||||
previous_slots: Dict[str, Any] = None,
|
||||
@@ -414,7 +426,7 @@ class AsyncIntentRecognizer:
|
||||
asyncio.create_task(self._generate_follow_up_questions_async(query, chat_history, conversation_context)),
|
||||
|
||||
# 5.3: HyDE
|
||||
asyncio.create_task(self._generate_hypothetical_document_async(query, chat_history, conversation_context)),
|
||||
# asyncio.create_task(self._generate_hypothetical_document_async(query, chat_history, conversation_context)),
|
||||
|
||||
# 5.4: 多问题查询
|
||||
asyncio.create_task(self._generate_multi_questions_async(query, chat_history, conversation_context))
|
||||
@@ -442,6 +454,13 @@ class AsyncIntentRecognizer:
|
||||
classification_task = self._classify_intent_async(rewrite.rewrite, conversation_context, chat_history, previous_slots)
|
||||
classification = await classification_task
|
||||
|
||||
# 特殊处理 锁相关咨询
|
||||
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
|
||||
logging.info(f"锁相关咨询正则匹配 - 总耗时: {process_lock_time:.2f}秒")
|
||||
# 步骤4: 进行槽位填充
|
||||
# 如果是有效分类,进行槽位填充
|
||||
slot_filling_result = {}
|
||||
@@ -464,24 +483,24 @@ class AsyncIntentRecognizer:
|
||||
logging.info(f"异步问题扩展环节耗时统计 - 总耗时: {end_time - start_time:.2f}秒")
|
||||
|
||||
# 收集结果
|
||||
step_back_result = query_expand_results[0] if query_expand_results[0] else StepBackPrompt(original_query=query, step_back_query=query)
|
||||
step_back_result = query_expand_results[0] if query_expand_results[0] else StepBackPrompt(original_query=query, can_use_back_prompt=False, step_back_query=[query])
|
||||
follow_up_result = query_expand_results[1] if query_expand_results[1] else FollowUpQuestions(original_query=query, follow_up_query=query)
|
||||
hyde_result = query_expand_results[2] if query_expand_results[2] else HypotheticalDocument(original_query=query, hypothetical_answer="")
|
||||
multi_questions_result = query_expand_results[3] if query_expand_results[3] else MultiQuestions(original_query=query, sub_questions=[query])
|
||||
# hyde_result = query_expand_results[2] if query_expand_results[2] else HypotheticalDocument(original_query=query, hypothetical_answer="")
|
||||
multi_questions_result = query_expand_results[2] if query_expand_results[2] else MultiQuestions(original_query=query, sub_questions=[query])
|
||||
|
||||
all_questions = multi_questions_result.sub_questions
|
||||
all_questions.append(query)
|
||||
all_questions.append(rewrite.rewrite)
|
||||
all_questions.extend(step_back_result.step_back_query)
|
||||
all_questions.append(follow_up_result.follow_up_query)
|
||||
all_questions.append(hyde_result.hypothetical_answer)
|
||||
# all_questions.append(hyde_result.hypothetical_answer)
|
||||
all_questions = list(set(all_questions))
|
||||
|
||||
query_expand = {
|
||||
"all": all_questions,
|
||||
"step_back": step_back_result.model_dump(),
|
||||
"follow_up": follow_up_result.model_dump(),
|
||||
"hyde": hyde_result.model_dump(),
|
||||
# "hyde": hyde_result.model_dump(),
|
||||
"multi_questions": multi_questions_result.model_dump()
|
||||
}
|
||||
|
||||
@@ -649,7 +668,7 @@ class AsyncIntentRecognizer:
|
||||
except Exception as e:
|
||||
# 如果解析失败,返回原始查询作为后退提示
|
||||
logging.error(f"异步后退提示生成失败: {e}", exc_info=True)
|
||||
return StepBackPrompt(original_query=query, step_back_query=query)
|
||||
return StepBackPrompt(original_query=query, can_use_back_prompt=False, step_back_query=[query])
|
||||
|
||||
async def _generate_follow_up_questions_async(self, query: str, chat_history: List[Dict[str, str]] = None, conversation_context: str = "") -> FollowUpQuestions:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user