diff --git a/app/core/config.py b/app/core/config.py index 8b7e7e8..3dc2132 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -175,3 +175,5 @@ PRIORITY_DICT = { 'bag_back': -98, 'earring_back': -99, } + +QWEN_API_KEY = "sk-a6bdf594e1f54a4aa3e9d4d48f8c661f" diff --git a/app/service/chat_robot/script/service/CallQWen.py b/app/service/chat_robot/script/service/CallQWen.py index 414e4ba..f8e6bd5 100644 --- a/app/service/chat_robot/script/service/CallQWen.py +++ b/app/service/chat_robot/script/service/CallQWen.py @@ -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 diff --git a/app/service/prompt_generation/chatgpt_for_translation.py b/app/service/prompt_generation/chatgpt_for_translation.py index d158c0f..fcf8ec5 100644 --- a/app/service/prompt_generation/chatgpt_for_translation.py +++ b/app/service/prompt_generation/chatgpt_for_translation.py @@ -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形式 diff --git a/requirements.txt b/requirements.txt index 51bd041..50dbfa2 100644 Binary files a/requirements.txt and b/requirements.txt differ