This commit is contained in:
2025-06-18 19:54:55 +08:00
parent 139d0cffef
commit 9fe4094f5b
29 changed files with 11 additions and 29 deletions
+9 -19
View File
@@ -110,6 +110,7 @@ class IntentRecognizer:
Returns:
分类结果
"""
classification_start_time = time.time()
classification_parser = PydanticOutputParser(pydantic_object=Classification)
formatted_prompt = classification_prompt.format(user_input=query,
classification_info=classification_info,
@@ -119,7 +120,9 @@ class IntentRecognizer:
# 调用LLM
response = self._llm.invoke(formatted_prompt, False)
classification_end_time = time.time()
classification_time = classification_end_time - classification_start_time
logging.info(f"意图分类耗时统计 - 总耗时: {classification_time:.2f}")
# 解析输出
try:
# 尝试直接解析JSON响应
@@ -442,9 +445,12 @@ class IntentRecognizer:
slot_model = self._get_slot_model(classification)
if not slot_model:
raise RuntimeError("未找到匹配的槽位模型")
fill_slots_start_time = time.time()
# 使用LLM进行槽位填充
filled_slots = self._fill_slots_with_llm(query, classification, slot_model, conversation_context, chat_history, previous_slots)
fill_slots_end_time = time.time()
fill_slots_time = fill_slots_end_time - fill_slots_start_time
logging.info(f"槽位填充耗时统计 - 总耗时: {fill_slots_time:.2f}")
# 检查必填槽位是否都已填充
is_complete, missing_slots = filled_slots.check_required_slots()
@@ -594,18 +600,8 @@ class IntentRecognizer:
if expected_slot_model is None:
# 添加容错处理,应对LLM返回错误分类信息,一级分类跟二级分类错乱
# 重新分类
classify_start_time = time.time()
classification = self._classify_intent(user_input, conversation_context, chat_history, previous_slots)
classify_end_time = time.time()
classify_time = classify_end_time - classify_start_time
# logging.info(f"重新分类耗时: {classify_time:.2f}秒")
fill_start_time = time.time()
fill_slots = self._fill_slots(user_input, classification, conversation_context, chat_history, previous_slots)
fill_end_time = time.time()
fill_time = fill_end_time - fill_start_time
all_time=fill_end_time-llm_start_time
logging.info(f"总耗时:{all_time:.2f}秒,首次槽位+分类:{llm_time:.2f}秒, 重新分类耗时: {classify_time:.2f}秒, 重新槽位填充耗时: {fill_time:.2f}")
result = {
"classification": classification.model_dump(),
@@ -615,13 +611,7 @@ class IntentRecognizer:
return result
elif expected_slot_model.__name__ != type(slot_filling).__name__:
# 添加容错处理,应对LLM槽位与分类不匹配。重新填充槽位
fill_start_time = time.time()
slot_filling = self._fill_slots(user_input, classification)
fill_end_time = time.time()
fill_time = fill_end_time - fill_start_time
all_time=fill_end_time-llm_start_time
logging.info(f"总耗时:{all_time:.2f}秒,首次槽位+分类:{llm_time:.2f}秒, 重新槽位填充耗时: {fill_time:.2f}")
slot_filling = self._fill_slots(user_input, classification, conversation_context, chat_history, previous_slots)
result = {
"classification": classification.model_dump(),
"slot_filling": slot_filling