diff --git a/AI/WxMini/Start.py b/AI/WxMini/Start.py index 8661a0de..0ffc6de1 100644 --- a/AI/WxMini/Start.py +++ b/AI/WxMini/Start.py @@ -275,8 +275,13 @@ async def reply(person_id: str = Form(...), except Exception as e: logger.error(f"查询失败: {e}") + # 在最后增加此人最近几条的交互记录数据 + recent_logs = get_chat_log_by_session(app.state.mysql_pool, person_id) + for record in recent_logs: + history_prompt += f"用户: {record['user_input']}\n大模型: {record['model_response']}\n" + # 限制历史交互提示词长度 - history_prompt = history_prompt[:2000] + history_prompt = history_prompt[:3000] # logger.info(f"历史交互提示词: {history_prompt}") # 调用大模型,将历史交互作为提示词 @@ -289,7 +294,7 @@ async def reply(person_id: str = Form(...), "content": "你是一个和你聊天人的好朋友,疏导情绪,让他开心,亲切一些,不要使用哎呀这样的语气词。聊天的回复内容不要超过100字。"}, {"role": "user", "content": f"历史对话记录:{history_prompt},本次用户问题: {prompt}"} ], - max_tokens=2000 + max_tokens=3000 ), timeout=60 # 设置超时时间为 60 秒 )