mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-14 05:15:18 +00:00
添加mem0的实现
This commit is contained in:
parent
dabbf320db
commit
043d6cb56b
1 changed files with 20 additions and 8 deletions
|
|
@ -1,4 +1,12 @@
|
|||
|
||||
from mem0 import MemoryClient
|
||||
import os
|
||||
from logging import getLogger
|
||||
log = getLogger(__name__)
|
||||
|
||||
mem0_api_key = os.getenv("MEM0_API_KEY")
|
||||
memory_client = MemoryClient(api_key=mem0_api_key)
|
||||
|
||||
async def mem0_search(user_id: str, chat_id: str, last_message: str) -> list[str]:
|
||||
"""
|
||||
预留的 Mem0 检索接口:当前为占位实现。
|
||||
|
|
@ -7,11 +15,14 @@ async def mem0_search(user_id: str, chat_id: str, last_message: str) -> list[str
|
|||
"""
|
||||
try:
|
||||
# TODO: 接入真实 Mem0 检索
|
||||
print("mem0_search")
|
||||
print("user_id:", user_id)
|
||||
print("chat_id:", chat_id)
|
||||
print("last_message:", last_message)
|
||||
return []
|
||||
log.info(f"mem0_search called with user_id: {user_id}, chat_id: {chat_id}, last_message: {last_message}")
|
||||
serach_rst = memory_client.search(
|
||||
query=last_message,
|
||||
filters={"user_id": user_id}
|
||||
)
|
||||
memories=serach_rst["results"] if "results" in serach_rst else serach_rst
|
||||
log.info(f"mem0_search found {len(memories)} memories")
|
||||
return [mem["text"] for mem in memories]
|
||||
except Exception as e:
|
||||
log.debug(f"Mem0 search failed: {e}")
|
||||
return []
|
||||
|
|
@ -24,9 +35,10 @@ async def mem0_delete(user_id: str, chat_id: str) -> bool:
|
|||
"""
|
||||
try:
|
||||
# TODO: 接入真实删除逻辑(如按 chat_id 过滤)
|
||||
print("mem0_delete")
|
||||
print("user_id:", user_id)
|
||||
print("chat_id:", chat_id)
|
||||
log.info(f"mem0_delete called with user_id: {user_id}, chat_id: {chat_id}")
|
||||
memory_client.delete(
|
||||
filters={"user_id": user_id}
|
||||
)
|
||||
return True
|
||||
except Exception as e:
|
||||
log.debug(f"Mem0 delete failed: {e}")
|
||||
|
|
|
|||
Loading…
Reference in a new issue