diff --git a/AI/WxMini/Start.py b/AI/WxMini/Start.py index dd62f9ba..ba99ec02 100644 --- a/AI/WxMini/Start.py +++ b/AI/WxMini/Start.py @@ -71,7 +71,6 @@ async def on_session_end(person_id): last_record = await cur.fetchone() if last_record: - # 拼接历史聊天记录 history = f"问题:{last_record[0]}\n回答:{last_record[1]}" else: history = "无聊天记录" @@ -341,8 +340,8 @@ async def reply(person_id: str = Form(...), await save_chat_to_mysql(app.state.mysql_pool, person_id, prompt, result, url, duration) #logger.info("用户输入和大模型反馈已记录到 MySQL 数据库。") - # 调用会话检查机制 - await on_session_end(person_id) + # 调用会话检查机制,异步执行 + asyncio.create_task(on_session_end(person_id)) # 返回数据 return { diff --git a/AI/WxMini/Utils/MySQLUtil.py b/AI/WxMini/Utils/MySQLUtil.py index 7a123f8b..b2fb6bba 100644 --- a/AI/WxMini/Utils/MySQLUtil.py +++ b/AI/WxMini/Utils/MySQLUtil.py @@ -78,7 +78,7 @@ async def get_chat_log_by_session(mysql_pool, current_user, person_id, page=1, p # 查询分页数据,按 id 降序排列 await cur.execute( - "SELECT SQL_NO_CACHE id, person_id, user_input, model_response, audio_url, duration, create_time " + "SELECT id, person_id, user_input, model_response, audio_url, duration, create_time " "FROM t_chat_log WHERE person_id = %s ORDER BY id DESC LIMIT %s OFFSET %s", (person_id, page_size, offset) ) @@ -184,8 +184,7 @@ async def get_chat_logs_by_risk_flag(mysql_pool, risk_flag: int, offset: int, pa async with conn.cursor() as cursor: # 查询符合条件的记录 sql = """ - SELECT SQL_NO_CACHE - tcl.id, tcl.user_input, tcl.model_response, tcl.audio_url, tcl.duration, + SELECT tcl.id, tcl.user_input, tcl.model_response, tcl.audio_url, tcl.duration, tcl.create_time, tcl.risk_flag, tcl.risk_memo, tcl.risk_result, tbp.person_id, tbp.login_name, tbp.person_name FROM t_chat_log AS tcl