mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-14 13:25:20 +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]:
|
async def mem0_search(user_id: str, chat_id: str, last_message: str) -> list[str]:
|
||||||
"""
|
"""
|
||||||
预留的 Mem0 检索接口:当前为占位实现。
|
预留的 Mem0 检索接口:当前为占位实现。
|
||||||
|
|
@ -7,11 +15,14 @@ async def mem0_search(user_id: str, chat_id: str, last_message: str) -> list[str
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# TODO: 接入真实 Mem0 检索
|
# TODO: 接入真实 Mem0 检索
|
||||||
print("mem0_search")
|
log.info(f"mem0_search called with user_id: {user_id}, chat_id: {chat_id}, last_message: {last_message}")
|
||||||
print("user_id:", user_id)
|
serach_rst = memory_client.search(
|
||||||
print("chat_id:", chat_id)
|
query=last_message,
|
||||||
print("last_message:", last_message)
|
filters={"user_id": user_id}
|
||||||
return []
|
)
|
||||||
|
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:
|
except Exception as e:
|
||||||
log.debug(f"Mem0 search failed: {e}")
|
log.debug(f"Mem0 search failed: {e}")
|
||||||
return []
|
return []
|
||||||
|
|
@ -24,9 +35,10 @@ async def mem0_delete(user_id: str, chat_id: str) -> bool:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# TODO: 接入真实删除逻辑(如按 chat_id 过滤)
|
# TODO: 接入真实删除逻辑(如按 chat_id 过滤)
|
||||||
print("mem0_delete")
|
log.info(f"mem0_delete called with user_id: {user_id}, chat_id: {chat_id}")
|
||||||
print("user_id:", user_id)
|
memory_client.delete(
|
||||||
print("chat_id:", chat_id)
|
filters={"user_id": user_id}
|
||||||
|
)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.debug(f"Mem0 delete failed: {e}")
|
log.debug(f"Mem0 delete failed: {e}")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue