import{_ as i,c as a,ae as n,o as t}from"./chunks/framework.BzDBnRMZ.js";const y=JSON.parse('{"title":"index","description":"","frontmatter":{"title":"index","order":100,"collapsed":true},"headers":[],"relativePath":"dev/api/tools/marshoai_memory/index.md","filePath":"zh/dev/api/tools/marshoai_memory/index.md","lastUpdated":null}'),h={name:"dev/api/tools/marshoai_memory/index.md"};function e(k,s,l,p,r,d){return t(),a("div",null,s[0]||(s[0]=[n(`
nonebot_plugin_marshoai.tools.marshoai_memory
write_memory(memory: str, user_id: str)
async def write_memory(memory: str, user_id: str):
with open(memory_path, 'r', encoding='utf-8') as f:
memory_data = json.load(f)
memorys = memory_data.get(user_id, [])
memorys.append(memory)
memory_data[user_id] = memorys
with open(memory_path, 'w', encoding='utf-8') as f:
json.dump(memory_data, f, ensure_ascii=False, indent=4)
return '记忆已经保存啦~'
read_memory(user_id: str)
async def read_memory(user_id: str):
with open(memory_path, 'r', encoding='utf-8') as f:
memory_data = json.load(f)
memorys = memory_data.get(user_id, [])
if not memorys:
return '好像对ta还没有任何记忆呢~'
return '这些是有关ta的记忆:' + '\\n'.join(memorys)
organize_memories()
async def organize_memories():
with open(memory_path, 'r', encoding='utf-8') as f:
memory_data = json.load(f)
for i in memory_data:
...