优化Dify工具逻辑,调整知识提取和重排序流程,增强API调用的重试机制,更新意图识别API以支持更好的错误处理和日志记录,改进多线程检索功能
This commit is contained in:
@@ -9,7 +9,6 @@ Description: 意图分类、改写核心逻辑
|
||||
|
||||
import logging
|
||||
import os
|
||||
import threading
|
||||
from langchain.output_parsers import PydanticOutputParser
|
||||
import json
|
||||
from typing import List, Tuple, Dict, Any, Optional
|
||||
@@ -449,10 +448,10 @@ class IntentRecognizer:
|
||||
"slot_filling": slot_filling_result
|
||||
}
|
||||
|
||||
# 等待所有线程完成
|
||||
# 等待所有greenlet完成
|
||||
start_time = time.time()
|
||||
for thread, _ in threads_and_results:
|
||||
thread.join()
|
||||
for greenlet, _ in threads_and_results:
|
||||
greenlet.join()
|
||||
end_time = time.time()
|
||||
logging.info(f"问题扩展环节耗时统计 - 总耗时: {end_time - start_time:.2f}秒")
|
||||
|
||||
@@ -751,7 +750,7 @@ class IntentRecognizer:
|
||||
|
||||
def _run_in_thread(self, func, args=(), kwargs={}):
|
||||
"""
|
||||
在线程中执行函数并返回结果
|
||||
在greenlet中执行函数并返回结果
|
||||
|
||||
Args:
|
||||
func: 要执行的函数
|
||||
@@ -759,21 +758,22 @@ class IntentRecognizer:
|
||||
kwargs: 函数的关键字参数
|
||||
|
||||
Returns:
|
||||
(thread, result_container): 线程对象和存放结果的容器
|
||||
(greenlet, result_container): greenlet对象和存放结果的容器
|
||||
"""
|
||||
from gevent import Greenlet
|
||||
result_container = []
|
||||
|
||||
def thread_target():
|
||||
def greenlet_target():
|
||||
try:
|
||||
result = func(*args, **kwargs)
|
||||
result_container.append(result)
|
||||
except Exception as e:
|
||||
logging.error(f"线程执行函数 {func.__name__} 时出错: {e}", exc_info=True)
|
||||
logging.error(f"greenlet执行函数 {func.__name__} 时出错: {e}", exc_info=True)
|
||||
result_container.append(None)
|
||||
|
||||
thread = threading.Thread(target=thread_target)
|
||||
thread.start()
|
||||
return thread, result_container
|
||||
greenlet = Greenlet(greenlet_target)
|
||||
greenlet.start()
|
||||
return greenlet, result_container
|
||||
|
||||
|
||||
def _process_intent_and_slot(self, user_input: str, conversation_context: str = "",
|
||||
|
||||
Reference in New Issue
Block a user