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

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

@@ -1,13 +1,11 @@
import logging
from dashscope import Generation
# from langchain.chains import LLMChain
from langchain_community.chat_models import QianfanChatEndpoint, ChatTongyi
# from langchain.chat_models import ChatOpenAI
from langchain_core.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate
from langchain_core.runnables import RunnableSequence
from requests import RequestException
from retry import retry
from app.core.config import QWEN_API_KEY
from app.core.config import OPENAI_MODEL, OPENAI_API_KEY
# os.environ["http_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
@retry(exceptions=RequestException, 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,
# seed=random.randint(1, 10000), # 设置随机数种子seed如果没有设置则随机数种子默认为1234
result_format='message', # 将输出设置为message形式