-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.py
More file actions
77 lines (43 loc) · 1.23 KB
/
Copy pathmemory.py
File metadata and controls
77 lines (43 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import json
from pathlib import Path
class AIMemory:
"""
Simple persistent memory for RepoForge.
"""
def __init__(self):
self.memory_dir = Path("memory/sessions")
self.memory_dir.mkdir(parents=True, exist_ok=True)
self.file = self.memory_dir / "latest.json"
def save(self, prompt, results):
data = {
"prompt": prompt,
"results": results,
}
with open(self.file, "w", encoding="utf-8") as f:
json.dump(
data,
f,
indent=4,
)
def load(self):
if not self.file.exists():
return None
with open(self.file, "r", encoding="utf-8") as f:
return json.load(f)
def has_memory(self):
return self.file.exists()
def clear(self):
if self.file.exists():
self.file.unlink()
if __name__ == "__main__":
memory = AIMemory()
memory.save(
"Build Netflix clone",
[
{
"task": "backend",
"response": "Completed."
}
]
)
print(memory.load())