perf(memory): store memories asynchronously to prevent blocking
Some checks failed
Build and Push Docker / build-and-push (push) Failing after 3m3s
Some checks failed
Build and Push Docker / build-and-push (push) Failing after 3m3s
This commit is contained in:
@ -126,7 +126,7 @@ In your response, consider the memories above to provide a personalized answer."
|
||||
|
||||
assistant_response = response.choices[0].message.content
|
||||
|
||||
# Step 5: Store the interaction as new memories
|
||||
# Step 5: Store the interaction as new memories (异步执行)
|
||||
messages = [
|
||||
{"role": "user", "content": user_input},
|
||||
{"role": "assistant", "content": assistant_response}
|
||||
@ -138,7 +138,16 @@ In your response, consider the memories above to provide a personalized answer."
|
||||
"type": "chat_interaction"
|
||||
}
|
||||
|
||||
self.add_memory(messages, user_id, metadata)
|
||||
# 异步存储记忆,不阻塞主流程
|
||||
def store_memory_async():
|
||||
try:
|
||||
self.add_memory(messages, user_id, metadata)
|
||||
except Exception as e:
|
||||
print(f"[WARNING] Async memory storage failed: {e}")
|
||||
|
||||
# 启动异步线程存储记忆
|
||||
memory_thread = threading.Thread(target=store_memory_async, daemon=True)
|
||||
memory_thread.start()
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
|
Reference in New Issue
Block a user