修复本地记忆存储记忆存储失败bug

This commit is contained in:
Ike-li 2025-03-27 19:37:57 +08:00
parent c66385d1f7
commit da4580b402

View file

@ -303,9 +303,16 @@ class ConnectionHandler:
future = self.executor.submit(self.speak_and_play, segment_text, text_index) future = self.executor.submit(self.speak_and_play, segment_text, text_index)
self.tts_queue.put(future) self.tts_queue.put(future)
# 存储对话内容
if len(response_message) > 0:
self.dialogue.put(Message(role="assistant", content="".join(response_message)))
# 异步保存记忆
asyncio.create_task(self.memory.save_memory(self.dialogue.dialogue))
self.llm_finish_task = True self.llm_finish_task = True
self.dialogue.put(Message(role="assistant", content="".join(response_message)))
self.logger.bind(tag=TAG).debug(json.dumps(self.dialogue.get_llm_dialogue(), indent=4, ensure_ascii=False)) self.logger.bind(tag=TAG).debug(json.dumps(self.dialogue.get_llm_dialogue(), indent=4, ensure_ascii=False))
return True return True
def chat_with_function_calling(self, query, tool_call=False): def chat_with_function_calling(self, query, tool_call=False):
@ -580,26 +587,16 @@ class ConnectionHandler:
self.tts_first_text_index = text_index self.tts_first_text_index = text_index
self.tts_last_text_index = text_index self.tts_last_text_index = text_index
async def close(self, ws=None): async def close(self, ws):
"""资源清理方法""" """关闭连接"""
try:
# 触发停止事件并清理资源
if self.stop_event:
self.stop_event.set()
# 立即关闭线程池
if self.executor:
self.executor.shutdown(wait=False, cancel_futures=True)
self.executor = None
# 清空任务队列
self._clear_queues()
if ws:
await ws.close() await ws.close()
elif self.websocket: except Exception as e:
await self.websocket.close() self.logger.bind(tag=TAG).error(f"关闭连接失败: {str(e)}")
self.logger.bind(tag=TAG).info("连接资源已释放") finally:
if ws in self.active_connections:
self.active_connections.remove(ws)
self.logger.bind(tag=TAG).info(f"连接已关闭 - Session: {self.session_id}")
def _clear_queues(self): def _clear_queues(self):
# 清空所有任务队列 # 清空所有任务队列