优化对话转工单功能,添加重试机制以提高稳定性,限制处理会话数量为前2000个,更新示例查询和文件路径,增强代码可读性和维护性。同时新增数据库客户端功能,支持批量处理会话数据并导出至Excel。

This commit is contained in:
2025-06-17 19:46:04 +08:00
parent a5c1548240
commit 22d48c951f
10 changed files with 718 additions and 96 deletions
+20 -8
View File
@@ -231,7 +231,7 @@ class DialogueToWorkorder:
output_format = self.user_question_and_solution_parser.get_format_instructions()
llm_prompt = prompt.format(output_format=output_format, dialogue_str=dialogue_str)
response = self.llm.invoke(user_prompt=llm_prompt)
response = self.llm.invoke(user_prompt=llm_prompt, need_retry=False)
try:
if response.content.count('user_question') == 1:
@@ -261,7 +261,7 @@ class DialogueToWorkorder:
except Exception as e:
output_format = self.user_question_and_solution_list_parser.get_format_instructions()
llm_prompt = prompt.format(output_format=output_format, dialogue_str=dialogue_str)
response = self.llm.invoke(user_prompt=llm_prompt)
response = self.llm.invoke(user_prompt=llm_prompt, need_retry=False)
user_question_and_solution_temp = self.user_question_and_solution_list_parser.parse(response.content)
return user_question_and_solution_temp.user_question_list
@@ -293,7 +293,7 @@ class DialogueToWorkorder:
{dialogue_str}
"""
response = self.llm.invoke(user_prompt=prompt)
response = self.llm.invoke(user_prompt=prompt, need_retry=False)
product_name_and_module_name = self.product_name_and_module_name_parser.parse(response.content)
return product_name_and_module_name.product_name, product_name_and_module_name.module_name
@@ -322,7 +322,7 @@ class DialogueToWorkorder:
{dialogue_str}
"""
response = self.llm.invoke(user_prompt=prompt)
response = self.llm.invoke(user_prompt=prompt, need_retry=False)
product_line = self.product_line_parser.parse(response.content)
return product_line.product_line
@@ -358,7 +358,7 @@ class DialogueToWorkorder:
{dialogue_str}
"""
response = self.llm.invoke(user_prompt=prompt)
response = self.llm.invoke(user_prompt=prompt, need_retry=False)
question_type = self.question_type_parser.parse(response.content)
return question_type.question_type
@@ -394,7 +394,7 @@ class DialogueToWorkorder:
"""
response = self.llm.invoke(user_prompt=prompt)
response = self.llm.invoke(user_prompt=prompt, need_retry=False)
is_complaint = self.is_complaint_parser.parse(response.content)
return (is_complaint.is_dissatisfaction,
@@ -479,7 +479,19 @@ class DialogueToWorkorder:
# 按会话ID分组
conversation_dict = self.group_conversations_by_id(df)
# 限制处理的会话数量为前2000个
if len(conversation_dict) > 2000:
print(f"会话总数为 {len(conversation_dict)},限制处理前2000个会话")
# 获取所有会话ID
conversation_ids = list(conversation_dict.keys())
# 只保留前2000个会话
limited_conversation_dict = {
conversation_id: conversation_dict[conversation_id]
for conversation_id in conversation_ids[:2000]
}
conversation_dict = limited_conversation_dict
else:
print(f"会话总数为 {len(conversation_dict)},处理全部会话")
# 使用线程池处理每个会话
workorder_dict_list = []
with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
@@ -593,7 +605,7 @@ def main():
args = parse_arguments()
# 设置默认文件路径
conversation_excel_path = args.conversation_file or os.path.join('data', 'excel', '会话内容详情20250528110230.xlsx')
conversation_excel_path = args.conversation_file or os.path.join('data', 'excel', '2025年1月到6月12号所有对话记录.xlsx')
product_detail_excel_path = args.product_detail_file or os.path.join('data', 'excel', '产品详情_工单.xlsx')
# 创建处理实例