优化Dify工具逻辑,调整知识提取和重排序流程,增强API调用的重试机制,更新意图识别API以支持更好的错误处理和日志记录,改进多线程检索功能
This commit is contained in:
@@ -219,12 +219,23 @@ reason: 简明扼要的理由(中文)
|
||||
|
||||
prompt = self.create_correctness_prompt(standard_answer, answer)
|
||||
llm = self.get_llm(response_format={"type": "json_object"})
|
||||
try:
|
||||
response = llm.invoke(user_prompt=prompt, need_retry=True)
|
||||
response_json = json.loads(response.content)
|
||||
return response_json["result"]
|
||||
except Exception as e:
|
||||
return None
|
||||
|
||||
max_retries = 3
|
||||
retry_count = 0
|
||||
|
||||
while retry_count < max_retries:
|
||||
try:
|
||||
response = llm.invoke(user_prompt=prompt, need_retry=True)
|
||||
response_json = json.loads(response.content)
|
||||
return response_json["result"]
|
||||
except Exception as e:
|
||||
retry_count += 1
|
||||
if retry_count >= max_retries:
|
||||
logging.error(f"判断答案失败,已重试{max_retries}次: {str(e)}")
|
||||
return False
|
||||
# 指数退避策略,每次重试等待时间增加
|
||||
import time
|
||||
time.sleep(1 * (2 ** (retry_count - 1))) # 1秒, 2秒, 4秒...
|
||||
|
||||
def judge_by_standard_answer(self, standard_answer: str, old_answer: str, new_answer: str) -> str | None:
|
||||
"""
|
||||
@@ -689,7 +700,7 @@ content: "{content}"
|
||||
if __name__ == "__main__":
|
||||
# 创建命令行参数解析器
|
||||
os.environ["DIFY_BASEURL"] = "http://10.1.16.39/v1"
|
||||
os.environ["DIFY_NEW_API_KEY"] = "app-qxsSybCs7ABiKlC1JabTYVn6"
|
||||
os.environ["DIFY_NEW_API_KEY"] = "app-rv6ie73Ufoa3nRYCMiJx3a8K"
|
||||
os.environ["DIFY_OLD_API_KEY"] = "app-wUdkWJx5zeOvmvBUZizMoSw3"
|
||||
|
||||
os.environ["DIFY_PG_HOST"] = "10.1.16.39"
|
||||
|
||||
Reference in New Issue
Block a user