翻译--添加连接失败时的重试

This commit is contained in:
2024-07-22 15:54:11 +08:00
committed by zhouchengrong
parent b92b1f7d6e
commit f4394cbc6a
4 changed files with 13 additions and 14 deletions

View File

@@ -2,6 +2,8 @@ import json
from typing import Dict, Any
from dashscope import Generation
from retry import retry
from urllib3.exceptions import NewConnectionError
from app.core.config import *
from app.service.chat_robot.script.callbacks.qwen_callback_handler import QWenCallbackHandler
@@ -107,8 +109,7 @@ qwen = QWenCallbackHandler()
def search_from_internet(message):
response = Generation.call(
model='qwen-turbo',
# api_key='sk-7658298c6b99443c98184a5e634fe6ab',
api_key='sk-a6bdf594e1f54a4aa3e9d4d48f8c661f',
api_key=QWEN_API_KEY,
messages=message,
tools=tools,
# seed=random.randint(1, 10000), # 设置随机数种子seed如果没有设置则随机数种子默认为1234
@@ -126,12 +127,11 @@ def get_table_info(table_names):
def query_database(sql_string):
return CustomDatabase.run(db, sql_string)
@retry(exceptions=NewConnectionError, tries=3, delay=1)
def get_response(messages):
response = Generation.call(
model='qwen-max',
# api_key='sk-7658298c6b99443c98184a5e634fe6ab',
api_key='sk-a6bdf594e1f54a4aa3e9d4d48f8c661f',
api_key=QWEN_API_KEY,
messages=messages,
tools=tools,
# seed=random.randint(1, 10000), # 设置随机数种子seed如果没有设置则随机数种子默认为1234