模块 nonebot_plugin_marshoai.tools.marshoai_memory
async func write_memory(memory: str, user_id: str)
源代码 或 在GitHub上查看
python
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 '记忆已经保存啦~'
async func read_memory(user_id: str)
源代码 或 在GitHub上查看
python
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)
async func organize_memories()
源代码 或 在GitHub上查看
python
async def organize_memories():
with open(memory_path, 'r', encoding='utf-8') as f:
memory_data = json.load(f)
for i in memory_data:
...