|
|
|
@ -27,13 +27,14 @@ async def init_mysql_pool():
|
|
|
|
|
|
|
|
|
|
# 保存聊天记录到 MySQL
|
|
|
|
|
async def save_chat_to_mysql(mysql_pool, person_id, prompt, result, audio_url, duration, input_type=1, output_type=1,
|
|
|
|
|
input_image_type=0):
|
|
|
|
|
input_image_type=0, image_width=0, image_height=0):
|
|
|
|
|
async with mysql_pool.acquire() as conn:
|
|
|
|
|
await conn.ping() # 重置连接
|
|
|
|
|
async with conn.cursor() as cur:
|
|
|
|
|
await cur.execute(
|
|
|
|
|
"INSERT INTO t_chat_log (person_id, user_input, model_response,audio_url,duration,input_type,output_type,input_image_type,create_time) VALUES (%s, %s, %s, %s, %s, %s, %s,%s,NOW())",
|
|
|
|
|
(person_id, prompt, result, audio_url, duration, input_type, output_type, input_image_type)
|
|
|
|
|
"INSERT INTO t_chat_log (person_id, user_input, model_response,audio_url,duration,input_type,output_type,input_image_type,image_width,image_height,create_time) VALUES (%s, %s, %s, %s, %s, %s, %s,%s,%s,%s,NOW())",
|
|
|
|
|
(person_id, prompt, result, audio_url, duration, input_type, output_type, input_image_type, image_width,
|
|
|
|
|
image_height)
|
|
|
|
|
)
|
|
|
|
|
await conn.commit()
|
|
|
|
|
|
|
|
|
@ -82,7 +83,7 @@ async def get_chat_log_by_session(mysql_pool, person_id, page=1, page_size=10):
|
|
|
|
|
|
|
|
|
|
# 查询分页数据,按 id 降序排列
|
|
|
|
|
await cur.execute(
|
|
|
|
|
"SELECT id, person_id, user_input, model_response, audio_url, duration,input_type,output_type,input_image_type, create_time "
|
|
|
|
|
"SELECT id, person_id, user_input, model_response, audio_url, duration,input_type,output_type,input_image_type,image_width,image_height, create_time "
|
|
|
|
|
"FROM t_chat_log WHERE person_id = %s ORDER BY id DESC LIMIT %s OFFSET %s",
|
|
|
|
|
(person_id, page_size, offset)
|
|
|
|
|
)
|
|
|
|
@ -103,6 +104,8 @@ async def get_chat_log_by_session(mysql_pool, person_id, page=1, page_size=10):
|
|
|
|
|
"duration": record['duration'],
|
|
|
|
|
"input_type": record['input_type'],
|
|
|
|
|
"output_type": record['output_type'],
|
|
|
|
|
"image_width": record['image_width'],
|
|
|
|
|
"image_height": record['image_height'],
|
|
|
|
|
"input_image_type": record['input_image_type'],
|
|
|
|
|
"create_time": record['create_time'].strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
}
|
|
|
|
|