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:
@@ -7,7 +7,7 @@ from dashscope import Generation
|
||||
from requests import RequestException
|
||||
from retry import retry
|
||||
|
||||
from app.core.config import QWEN_API_KEY
|
||||
from app.core.config import settings
|
||||
from app.service.chat_robot.script.service.CallQWen import get_language
|
||||
from app.service.prompt_generation.util import minio_util
|
||||
|
||||
@@ -51,19 +51,19 @@ def translate_to_en(text):
|
||||
# "The translation of \"Material suave\" into English would be \"Smooth material.\"". Instead, directly output "Smooth material".
|
||||
# """
|
||||
# )
|
||||
messages = [
|
||||
# {
|
||||
# Translate the entire text and ensure the output is a complete and coherent sentence in English.
|
||||
# "content": template, # 系统message
|
||||
# "role": "system"
|
||||
# },
|
||||
{
|
||||
# "content": input('请输入:'), # 用户message
|
||||
"content": text, # 用户message
|
||||
"role": "user"
|
||||
}
|
||||
]
|
||||
first_response = get_response(messages)
|
||||
# messages = [
|
||||
# # {
|
||||
# # Translate the entire text and ensure the output is a complete and coherent sentence in English.
|
||||
# # "content": template, # 系统message
|
||||
# # "role": "system"
|
||||
# # },
|
||||
# {
|
||||
# # "content": input('请输入:'), # 用户message
|
||||
# "content": text, # 用户message
|
||||
# "role": "user"
|
||||
# }
|
||||
# ]
|
||||
first_response = get_response
|
||||
assistant_output = first_response.output.choices[0].message
|
||||
print("input : {}, translate result : {}".format(text, assistant_output.content))
|
||||
return assistant_output.content
|
||||
@@ -79,7 +79,7 @@ def translate_to_en(text):
|
||||
def get_response(messages):
|
||||
response = Generation.call(
|
||||
model='qwen-turbo',
|
||||
api_key=QWEN_API_KEY,
|
||||
api_key=settings.QWEN_API_KEY,
|
||||
messages=messages,
|
||||
# seed=random.randint(1, 10000), # 设置随机数种子seed,如果没有设置,则随机数种子默认为1234
|
||||
result_format='message', # 将输出设置为message形式
|
||||
@@ -122,6 +122,7 @@ def get_translation_from_llama3(text):
|
||||
logger.info(f"translation server runtime is {time.time() - start_time} , response is {response.content}")
|
||||
print(f"Request failed with status code {response.status_code}")
|
||||
print(response.text)
|
||||
return ""
|
||||
|
||||
|
||||
# 在llama3中创建一个翻译模型
|
||||
@@ -174,6 +175,7 @@ def get_prompt_from_image(image_path, text):
|
||||
logger.info(f"sketch re-generate server runtime is {time.time() - start_time} , response is {response.content}")
|
||||
print(f"Request failed with status code {response.status_code}")
|
||||
print(response.text)
|
||||
return ""
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -2,20 +2,19 @@ import base64
|
||||
|
||||
from minio import Minio
|
||||
|
||||
from app.core.config import MINIO_URL, MINIO_ACCESS, MINIO_SECRET, MINIO_SECURE
|
||||
from app.core.config import settings
|
||||
|
||||
minio_client = Minio(MINIO_URL, access_key=MINIO_ACCESS, secret_key=MINIO_SECRET, secure=MINIO_SECURE)
|
||||
minio_client = Minio(settings.MINIO_URL, access_key=settings.MINIO_ACCESS, secret_key=settings.MINIO_SECRET, secure=settings.MINIO_SECURE)
|
||||
|
||||
|
||||
def minio_url_to_base64(minio_url: str) -> str:
|
||||
bucket_name, object_name = minio_url.split("/", 1)
|
||||
|
||||
response = minio_client.get_object(bucket_name, object_name)
|
||||
try:
|
||||
response = minio_client.get_object(bucket_name, object_name)
|
||||
image_data = response.read()
|
||||
return base64.b64encode(image_data).decode('utf-8')
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to get object: {e}")
|
||||
finally:
|
||||
if 'response' in locals():
|
||||
response.close()
|
||||
response.close()
|
||||
|
||||
Reference in New Issue
Block a user