上传
This commit is contained in:
@@ -73,11 +73,4 @@ n. [Final action]
|
|||||||
您无权在声明模式之外做出独立决定
|
您无权在声明模式之外做出独立决定
|
||||||
不遵守此协议将给我的代码库带来灾难性的后果
|
不遵守此协议将给我的代码库带来灾难性的后果
|
||||||
模式转换信号
|
模式转换信号
|
||||||
仅当我明确发出信号时才转换模式:
|
按照顺序依次执行研究模式->计划模式->执行模式->审核模式
|
||||||
|
|
||||||
“进入研究模式”
|
|
||||||
“进入创新模式”
|
|
||||||
“进入计划模式”
|
|
||||||
“进入执行模式”
|
|
||||||
“进入审核模式”
|
|
||||||
如果没有这些确切的信号,请保持当前模式。
|
|
||||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+1
-2
@@ -176,8 +176,7 @@ def save_results_to_excel(results, output_file, is_final=False):
|
|||||||
logging.info(f"已保存{len(valid_results)}条结果至: {temp_output_file}")
|
logging.info(f"已保存{len(valid_results)}条结果至: {temp_output_file}")
|
||||||
|
|
||||||
# 示例查询
|
# 示例查询
|
||||||
examples_query = """那储能软件如何操作"""
|
examples_query = """.BDD3是哪款软件编制的"""
|
||||||
examples_query = """博微软件如何新建工程啊"""
|
|
||||||
conversation_context=""
|
conversation_context=""
|
||||||
chat_history=[
|
chat_history=[
|
||||||
{
|
{
|
||||||
|
|||||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+9
-19
@@ -110,6 +110,7 @@ class IntentRecognizer:
|
|||||||
Returns:
|
Returns:
|
||||||
分类结果
|
分类结果
|
||||||
"""
|
"""
|
||||||
|
classification_start_time = time.time()
|
||||||
classification_parser = PydanticOutputParser(pydantic_object=Classification)
|
classification_parser = PydanticOutputParser(pydantic_object=Classification)
|
||||||
formatted_prompt = classification_prompt.format(user_input=query,
|
formatted_prompt = classification_prompt.format(user_input=query,
|
||||||
classification_info=classification_info,
|
classification_info=classification_info,
|
||||||
@@ -119,7 +120,9 @@ class IntentRecognizer:
|
|||||||
|
|
||||||
# 调用LLM
|
# 调用LLM
|
||||||
response = self._llm.invoke(formatted_prompt, False)
|
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:
|
try:
|
||||||
# 尝试直接解析JSON响应
|
# 尝试直接解析JSON响应
|
||||||
@@ -442,9 +445,12 @@ class IntentRecognizer:
|
|||||||
slot_model = self._get_slot_model(classification)
|
slot_model = self._get_slot_model(classification)
|
||||||
if not slot_model:
|
if not slot_model:
|
||||||
raise RuntimeError("未找到匹配的槽位模型")
|
raise RuntimeError("未找到匹配的槽位模型")
|
||||||
|
fill_slots_start_time = time.time()
|
||||||
# 使用LLM进行槽位填充
|
# 使用LLM进行槽位填充
|
||||||
filled_slots = self._fill_slots_with_llm(query, classification, slot_model, conversation_context, chat_history, previous_slots)
|
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()
|
is_complete, missing_slots = filled_slots.check_required_slots()
|
||||||
@@ -594,18 +600,8 @@ class IntentRecognizer:
|
|||||||
if expected_slot_model is None:
|
if expected_slot_model is None:
|
||||||
# 添加容错处理,应对LLM返回错误分类信息,一级分类跟二级分类错乱
|
# 添加容错处理,应对LLM返回错误分类信息,一级分类跟二级分类错乱
|
||||||
# 重新分类
|
# 重新分类
|
||||||
classify_start_time = time.time()
|
|
||||||
classification = self._classify_intent(user_input, conversation_context, chat_history, previous_slots)
|
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_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 = {
|
result = {
|
||||||
"classification": classification.model_dump(),
|
"classification": classification.model_dump(),
|
||||||
@@ -615,13 +611,7 @@ class IntentRecognizer:
|
|||||||
return result
|
return result
|
||||||
elif expected_slot_model.__name__ != type(slot_filling).__name__:
|
elif expected_slot_model.__name__ != type(slot_filling).__name__:
|
||||||
# 添加容错处理,应对LLM槽位与分类不匹配。重新填充槽位
|
# 添加容错处理,应对LLM槽位与分类不匹配。重新填充槽位
|
||||||
fill_start_time = time.time()
|
slot_filling = self._fill_slots(user_input, classification, conversation_context, chat_history, previous_slots)
|
||||||
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}秒")
|
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
"classification": classification.model_dump(),
|
"classification": classification.model_dump(),
|
||||||
"slot_filling": slot_filling
|
"slot_filling": slot_filling
|
||||||
|
|||||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Reference in New Issue
Block a user