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

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

@@ -175,3 +175,5 @@ PRIORITY_DICT = {
'bag_back': -98, 'bag_back': -98,
'earring_back': -99, 'earring_back': -99,
} }
QWEN_API_KEY = "sk-a6bdf594e1f54a4aa3e9d4d48f8c661f"

View File

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

View File

@@ -1,13 +1,11 @@
import logging import logging
from dashscope import Generation from dashscope import Generation
# from langchain.chains import LLMChain from requests import RequestException
from langchain_community.chat_models import QianfanChatEndpoint, ChatTongyi from retry import retry
# from langchain.chat_models import ChatOpenAI
from langchain_core.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate from app.core.config import QWEN_API_KEY
from langchain_core.runnables import RunnableSequence
from app.core.config import OPENAI_MODEL, OPENAI_API_KEY
# os.environ["http_proxy"] = "http://127.0.0.1:7890" # os.environ["http_proxy"] = "http://127.0.0.1:7890"
# os.environ["https_proxy"] = "http://127.0.0.1:7890" # os.environ["https_proxy"] = "http://127.0.0.1:7890"
@@ -44,12 +42,11 @@ def translate_to_en(text):
return assistant_output.content return assistant_output.content
@retry(exceptions=RequestException, tries=3, delay=1)
def get_response(messages): def get_response(messages):
response = Generation.call( response = Generation.call(
model='qwen-max', model='qwen-max',
# api_key='sk-7658298c6b99443c98184a5e634fe6ab', api_key= QWEN_API_KEY,
api_key='sk-a6bdf594e1f54a4aa3e9d4d48f8c661f',
messages=messages, messages=messages,
# seed=random.randint(1, 10000), # 设置随机数种子seed如果没有设置则随机数种子默认为1234 # seed=random.randint(1, 10000), # 设置随机数种子seed如果没有设置则随机数种子默认为1234
result_format='message', # 将输出设置为message形式 result_format='message', # 将输出设置为message形式

Binary file not shown.