main
HuangHai 4 months ago
parent 63bf9ec524
commit e2eeeab982

@ -246,6 +246,21 @@ async def reply(person_id: str = Form(...),
"message": "请输入内容",
"success": False
}
if '生成图片' in prompt or '生图' in prompt:
success, key = generate_image(prompt)
if success:
# 记录聊天数据到 MySQL
await save_chat_to_mysql(app.state.mysql_pool, person_id, prompt,
key, '', 0)
# 返回数据
return {
"success": True,
"url": None,
"duration": 0, # 返回大模型的回复时长
"response": key, # 返回大模型的回复
}
# 从连接池中获取一个连接
connection = milvus_pool.get_connection()
@ -374,8 +389,6 @@ async def reply(person_id: str = Form(...),
"search_time": end_time - start_time, # 返回查询耗时
"duration": duration, # 返回大模型的回复时长
"response": result, # 返回大模型的回复
"login_name": current_user["login_name"],
"person_name": current_user["person_name"]
}
else:
raise HTTPException(status_code=500, detail="大模型未返回有效结果")

@ -4,5 +4,4 @@ from WxMini.Utils.ImageUtil import generate_image
if __name__ == '__main__':
prompt = "武松打虎"
success, message = generate_image(prompt)
if not success:
print(f"生成失败: {message}")
print(message)

@ -8,7 +8,6 @@ import oss2
from WxMini.Milvus.Config.MulvusConfig import *
def generate_image(prompt, model="wanx2.1-t2i-turbo", n=1, size='1024*1024'):
# 初始化 OSS 客户端
auth = oss2.Auth(ACCESS_KEY_ID, ACCESS_KEY_SECRET)
@ -33,9 +32,9 @@ def generate_image(prompt, model="wanx2.1-t2i-turbo", n=1, size='1024*1024'):
# 生成 OSS 文件名
file_name = PurePosixPath(unquote(urlparse(image_url).path)).parts[-1]
# 上传到 OSS
bucket.put_object('Upload/' + file_name, image_data)
print(f"图片已上传到 OSS文件名: Upload/{file_name}")
return True, "图片生成并上传成功"
key = 'Upload/' + file_name
bucket.put_object(key, image_data)
return True, f'{OSS_PREFIX}{key}'
else:
# 生成失败,返回错误信息
error_message = f"同步调用失败,状态码: {rsp.status_code}, 错误码: {rsp.code}, 错误信息: {rsp.message}"

Loading…
Cancel
Save