feat : 代码梳理 移除所有敏感密钥 通过环境变量方式配置
All checks were successful
git commit AiDA python develop 分支构建部署 / scheduled_deploy (push) Has been skipped
All checks were successful
git commit AiDA python develop 分支构建部署 / scheduled_deploy (push) Has been skipped
This commit is contained in:
@@ -5,10 +5,10 @@ from dashscope import Generation
|
||||
from retry import retry
|
||||
from urllib3.exceptions import NewConnectionError
|
||||
|
||||
from app.core.config import *
|
||||
from app.core.config import settings
|
||||
from app.service.chat_robot.script.callbacks.qwen_callback_handler import QWenCallbackHandler
|
||||
from app.service.chat_robot.script.database import CustomDatabase
|
||||
from app.service.chat_robot.script.prompt import FASHION_CHAT_BOT_PREFIX, TOOLS_FUNCTIONS_SUFFIX, TUTORIAL_TOOL_RETURN, \
|
||||
from app.service.chat_robot.script.prompt import TOOLS_FUNCTIONS_SUFFIX, TUTORIAL_TOOL_RETURN, \
|
||||
GET_LANGUAGE_PREFIX, FASHION_CHAT_BOT_PREFIX_TEMP
|
||||
from app.service.search_image_with_text.service import query
|
||||
|
||||
@@ -149,7 +149,7 @@ tools = [
|
||||
}
|
||||
]
|
||||
|
||||
db = CustomDatabase.from_uri(f'mysql+pymysql://{DB_USERNAME}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/attribute_retrieval_V3',
|
||||
db = CustomDatabase.from_uri(f'mysql+pymysql://{settings.MYSQL_USER}:{settings.MYSQL_PASSWORD}@{settings.MYSQL_HOST}:{settings.MYSQL_PORT}/attribute_retrieval_V3',
|
||||
include_tables=['female_top', 'female_skirt', 'female_pants', 'female_dress',
|
||||
'female_outwear', 'male_bottom', 'male_top', 'male_outwear'],
|
||||
engine_args={"pool_recycle": 7200})
|
||||
@@ -159,7 +159,7 @@ qwen = QWenCallbackHandler()
|
||||
def search_from_internet(message):
|
||||
response = Generation.call(
|
||||
model='qwen-turbo',
|
||||
api_key=QWEN_API_KEY,
|
||||
api_key=settings.QWEN_API_KEY,
|
||||
messages=message,
|
||||
prompt='The output must be in English.Keep the final result under 200 words.'
|
||||
# tools=tools,
|
||||
@@ -190,7 +190,7 @@ def get_image_from_vector_db(gender, content):
|
||||
def get_response(messages):
|
||||
response = Generation.call(
|
||||
model='qwen-max',
|
||||
api_key=QWEN_API_KEY,
|
||||
api_key=settings.QWEN_API_KEY,
|
||||
messages=messages,
|
||||
tools=tools,
|
||||
# seed=random.randint(1, 10000), # 设置随机数种子seed,如果没有设置,则随机数种子默认为1234
|
||||
@@ -203,7 +203,7 @@ def get_response(messages):
|
||||
def get_assistant_response(messages):
|
||||
response = Generation.call(
|
||||
model='qwen-max',
|
||||
api_key=QWEN_API_KEY,
|
||||
api_key=settings.QWEN_API_KEY,
|
||||
messages=messages,
|
||||
# seed=random.randint(1, 10000), # 设置随机数种子seed,如果没有设置,则随机数种子默认为1234
|
||||
result_format='message', # 将输出设置为message形式
|
||||
@@ -212,8 +212,10 @@ def get_assistant_response(messages):
|
||||
return response
|
||||
|
||||
|
||||
global tool_info
|
||||
|
||||
|
||||
def call_with_messages(message):
|
||||
global tool_info
|
||||
user_input = message
|
||||
print('\n')
|
||||
|
||||
@@ -241,7 +243,7 @@ def call_with_messages(message):
|
||||
response_type = "chat"
|
||||
|
||||
while flag and count <= 3:
|
||||
first_response = get_response(messages)
|
||||
first_response = get_response
|
||||
assistant_output = first_response.output.choices[0].message
|
||||
QWenCallbackHandler.on_llm_end(qwen, first_response.usage)
|
||||
print(f"\n大模型第 {count} 轮输出信息:{first_response}\n")
|
||||
@@ -260,7 +262,7 @@ def call_with_messages(message):
|
||||
]
|
||||
tool_info['content'] = search_from_internet(message)
|
||||
flag = False
|
||||
result_content = tool_info['content'].output.text
|
||||
result_content = tool_info['content']
|
||||
# 如果模型选择的工具是get_database_table
|
||||
# elif assistant_output.tool_calls[0]['function']['name'] == 'get_database_table':
|
||||
# tool_info = {"name": "get_database_table", "role": "tool", 'content': get_database_table()}
|
||||
|
||||
Reference in New Issue
Block a user