Spaces:
Running
Running
File size: 425 Bytes
ca65aec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# utils/memory.py
import json
import os
import time
FILE = "memory.json"
def load():
if os.path.exists(FILE):
with open(FILE) as f:
return json.load(f)
return []
def save(history):
with open(FILE, "w") as f:
json.dump(history[-5:], f)
def remember(message, reply):
data = load()
data.append({"t": int(time.time()), "u": message, "a": reply})
save(data)
return data
|