优化对话到工单的处理逻辑,新增进度条显示,调整日期参数的默认值,并修复日志目录创建的冗余代码。同时,更新DifyExporter类以支持按日期范围过滤消息,重构查询日志加载逻辑,新增备注提取功能,提升代码可读性和可维护性。
This commit is contained in:
@@ -288,8 +288,10 @@ class AsyncIntentRecognizer:
|
||||
# 步骤2: 使用向量检索找到相似的专业名词
|
||||
try:
|
||||
vector_start_time = time.time()
|
||||
# 对matched_terms中的每个关键字进行向量检索
|
||||
for current_key in query_keys:
|
||||
|
||||
# 创建并行任务列表
|
||||
async def process_single_keyword(current_key: str) -> List[Term]:
|
||||
"""处理单个关键词的向量检索和重排序"""
|
||||
vector_results = await self._noun_retriever.query_async(current_key, top_k=5, use_intersection=False)
|
||||
current_key_terms = set()
|
||||
# 添加向量检索结果
|
||||
@@ -304,7 +306,17 @@ class AsyncIntentRecognizer:
|
||||
current_key_terms.add(term)
|
||||
if len(current_key_terms) > 0:
|
||||
reranked_terms = await self._rerank_matched_terms_async(current_key, current_key_terms)
|
||||
matched_terms.extend(reranked_terms)
|
||||
return reranked_terms
|
||||
return []
|
||||
|
||||
# 并行处理所有关键词
|
||||
keyword_tasks = [process_single_keyword(current_key) for current_key in query_keys]
|
||||
keyword_results = await asyncio.gather(*keyword_tasks)
|
||||
|
||||
# 合并所有结果
|
||||
for result in keyword_results:
|
||||
matched_terms.extend(result)
|
||||
|
||||
vector_end_time = time.time()
|
||||
vector_time = vector_end_time - vector_start_time
|
||||
except Exception as e:
|
||||
@@ -649,7 +661,7 @@ class AsyncIntentRecognizer:
|
||||
formatted_prompt = step_back_prompt.format(
|
||||
query=query,
|
||||
chat_history=json.dumps(chat_history, ensure_ascii=False) if chat_history else "[]",
|
||||
conversation_context=conversation_context,
|
||||
# conversation_context=conversation_context,
|
||||
output_format=step_back_parser.get_format_instructions()
|
||||
)
|
||||
|
||||
@@ -688,7 +700,7 @@ class AsyncIntentRecognizer:
|
||||
formatted_prompt = follow_up_questions_prompt.format(
|
||||
query=query,
|
||||
chat_history=json.dumps(chat_history, ensure_ascii=False) if chat_history else "[]",
|
||||
conversation_context=conversation_context,
|
||||
# conversation_context=conversation_context,
|
||||
output_format=follow_up_parser.get_format_instructions()
|
||||
)
|
||||
|
||||
@@ -727,7 +739,7 @@ class AsyncIntentRecognizer:
|
||||
formatted_prompt = hyde_prompt.format(
|
||||
query=query,
|
||||
chat_history=json.dumps(chat_history, ensure_ascii=False) if chat_history else "[]",
|
||||
conversation_context=conversation_context,
|
||||
# conversation_context=conversation_context,
|
||||
output_format=hyde_parser.get_format_instructions()
|
||||
)
|
||||
|
||||
@@ -766,7 +778,7 @@ class AsyncIntentRecognizer:
|
||||
formatted_prompt = multi_questions_prompt.format(
|
||||
query=query,
|
||||
chat_history=json.dumps(chat_history, ensure_ascii=False) if chat_history else "[]",
|
||||
conversation_context=conversation_context,
|
||||
# conversation_context=conversation_context,
|
||||
output_format=multi_questions_parser.get_format_instructions()
|
||||
)
|
||||
|
||||
|
||||
@@ -226,30 +226,30 @@ step_back_prompt = """
|
||||
- 涵盖原始问题的核心主题
|
||||
- 去除过于具体的限制条件(如时间、地点、特定版本、特定工程等)
|
||||
- 保持在同一领域和主题范围内
|
||||
- 依次移除问题中的限定词或者修饰词
|
||||
|
||||
## 输入
|
||||
用户原始问题: {query}
|
||||
历史对话记录: {chat_history}
|
||||
会话背景: {conversation_context}
|
||||
|
||||
## 输出格式
|
||||
{output_format}
|
||||
|
||||
## 示例
|
||||
原始问题: "配网D3软件2023版本如何在Windows 11系统上导入单位工程量清单?"
|
||||
原始问题: "2023版本如何在Windows 11系统上导入单位工程量清单?"
|
||||
后退问题:
|
||||
{{
|
||||
"original_query": "配网D3软件2023版本如何在Windows 11系统上导入单位工程量清单?",
|
||||
"original_query": "2023版本如何在Windows 11系统上导入单位工程量清单?",
|
||||
"can_use_back_prompt": True,
|
||||
"step_back_query": ["配网D3软件如何导入工程量清单?", "如何导入单位工程量清单?"]
|
||||
"step_back_query": ["如何在Windows 11系统上导入单位工程量清单?", "如何导入单位工程量清单?"]
|
||||
}}
|
||||
|
||||
原始问题: "技改T1软件中的某个设备更换后,如何在系统中更新对应的定额?"
|
||||
原始问题: "某个设备更换后,如何在系统中更新对应的定额?"
|
||||
后退问题:
|
||||
{{
|
||||
"original_query": "技改T1软件中的某个设备更换后,如何在系统中更新对应的定额?",
|
||||
"original_query": "某个设备更换后,如何在系统中更新对应的定额?",
|
||||
"can_use_back_prompt": True,
|
||||
"step_back_query": ["技改T1软件中如何更新设备对应的定额?", "如何更新设备对应的定额?"]
|
||||
"step_back_query": ["如何更新设备对应的定额?", "如何更新定额?"]
|
||||
}}
|
||||
|
||||
"""
|
||||
@@ -271,7 +271,6 @@ follow_up_questions_prompt = """
|
||||
## 输入
|
||||
历史对话记录: {chat_history}
|
||||
当前用户问题: {query}
|
||||
会话背景: {conversation_context}
|
||||
|
||||
## 输出格式
|
||||
{output_format}
|
||||
@@ -308,7 +307,6 @@ hyde_prompt = """
|
||||
## 输入
|
||||
用户问题: {query}
|
||||
历史对话记录: {chat_history}
|
||||
会话背景: {conversation_context}
|
||||
|
||||
## 输出格式
|
||||
{output_format}
|
||||
@@ -343,7 +341,6 @@ multi_questions_prompt = """
|
||||
## 输入
|
||||
用户原始问题: {query}
|
||||
历史对话记录: {chat_history}
|
||||
会话背景: {conversation_context}
|
||||
|
||||
## 输出格式
|
||||
{output_format}
|
||||
|
||||
Reference in New Issue
Block a user