|
|
|
@ -26,13 +26,14 @@ async def init_mysql_pool():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 保存聊天记录到 MySQL
|
|
|
|
|
async def save_chat_to_mysql(mysql_pool, person_id, prompt, result, audio_url, duration):
|
|
|
|
|
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):
|
|
|
|
|
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,create_time) VALUES (%s, %s, %s, %s, %s,NOW())",
|
|
|
|
|
(person_id, prompt, result, audio_url, duration)
|
|
|
|
|
"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)
|
|
|
|
|
)
|
|
|
|
|
await conn.commit()
|
|
|
|
|
|
|
|
|
@ -81,7 +82,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, create_time "
|
|
|
|
|
"SELECT id, person_id, user_input, model_response, audio_url, duration,input_type,output_type,input_image_type, create_time "
|
|
|
|
|
"FROM t_chat_log WHERE person_id = %s ORDER BY id DESC LIMIT %s OFFSET %s",
|
|
|
|
|
(person_id, page_size, offset)
|
|
|
|
|
)
|
|
|
|
@ -256,7 +257,7 @@ async def get_chat_logs_by_risk_flag(mysql_pool, risk_flag: int, person_id: str,
|
|
|
|
|
INNER JOIN t_base_person AS tbp ON tcl.person_id = tbp.person_id
|
|
|
|
|
WHERE tcl.risk_flag = %s and tcl.person_id=%s
|
|
|
|
|
"""
|
|
|
|
|
await cursor.execute(count_sql, (risk_flag,person_id))
|
|
|
|
|
await cursor.execute(count_sql, (risk_flag, person_id))
|
|
|
|
|
total = (await cursor.fetchone())[0]
|
|
|
|
|
|
|
|
|
|
# 将元组转换为字典,并格式化 create_time
|
|
|
|
|