|
|
|
@ -237,6 +237,7 @@ async def reply(person_id: str = Form(...),
|
|
|
|
|
:param prompt: 用户输入的 prompt
|
|
|
|
|
:return: 大模型的回复
|
|
|
|
|
"""
|
|
|
|
|
logger.info(f"current_user= {current_user}")
|
|
|
|
|
try:
|
|
|
|
|
logger.info(f"收到用户输入: {prompt}")
|
|
|
|
|
|
|
|
|
@ -250,9 +251,12 @@ async def reply(person_id: str = Form(...),
|
|
|
|
|
if '生成图片' in prompt or '生图' in prompt:
|
|
|
|
|
success, key = generate_image(prompt)
|
|
|
|
|
if success:
|
|
|
|
|
image_url = f"{OSS_PREFIX}{key}"
|
|
|
|
|
image_width, image_height = getImgWidthHeight(image_url)
|
|
|
|
|
# 记录聊天数据到 MySQL
|
|
|
|
|
await save_chat_to_mysql(app.state.mysql_pool, person_id, prompt,
|
|
|
|
|
key, '', 0)
|
|
|
|
|
key, '', 0, input_type=2, output_type=4,
|
|
|
|
|
input_image_type=0, image_width=image_width, image_height=image_height)
|
|
|
|
|
# 返回数据
|
|
|
|
|
return {
|
|
|
|
|
"success": True,
|
|
|
|
@ -377,7 +381,7 @@ async def reply(person_id: str = Form(...),
|
|
|
|
|
|
|
|
|
|
# 记录聊天数据到 MySQL
|
|
|
|
|
await save_chat_to_mysql(app.state.mysql_pool, person_id, prompt, result, url, duration)
|
|
|
|
|
# logger.info("用户输入和大模型反馈已记录到 MySQL 数据库。")
|
|
|
|
|
logger.info("用户输入和大模型反馈已记录到 MySQL 数据库。")
|
|
|
|
|
|
|
|
|
|
# 调用会话检查机制,异步执行
|
|
|
|
|
asyncio.create_task(on_session_end(person_id))
|
|
|
|
@ -397,7 +401,8 @@ async def reply(person_id: str = Form(...),
|
|
|
|
|
raise HTTPException(status_code=500, detail=f"调用大模型失败: {str(e)}")
|
|
|
|
|
finally:
|
|
|
|
|
# 释放连接
|
|
|
|
|
milvus_pool.release_connection(connection)
|
|
|
|
|
if 'connection' in locals() and connection: # 检查 connection 是否已定义且不为 None
|
|
|
|
|
milvus_pool.release_connection(connection)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取聊天记录
|
|
|
|
|