Spaces:
Runtime error
Runtime error
Update memory.py
Browse files
memory.py
CHANGED
@@ -1,9 +1,7 @@
|
|
1 |
import json
|
2 |
|
3 |
-
# Memory file ka path
|
4 |
MEMORY_FILE = "memory.json"
|
5 |
|
6 |
-
# Pehle se stored memory load karna
|
7 |
def load_memory():
|
8 |
try:
|
9 |
with open(MEMORY_FILE, "r", encoding="utf-8") as f:
|
@@ -11,18 +9,15 @@ def load_memory():
|
|
11 |
except FileNotFoundError:
|
12 |
return {}
|
13 |
|
14 |
-
# Memory save karna
|
15 |
def save_memory(memory):
|
16 |
with open(MEMORY_FILE, "w", encoding="utf-8") as f:
|
17 |
json.dump(memory, f, indent=4)
|
18 |
|
19 |
-
# Conversation yaad rakhna
|
20 |
def update_memory(user_input, bot_response):
|
21 |
memory = load_memory()
|
22 |
memory[user_input] = bot_response
|
23 |
save_memory(memory)
|
24 |
|
25 |
-
# Pehle se existing response check karna
|
26 |
def check_memory(user_input):
|
27 |
memory = load_memory()
|
28 |
return memory.get(user_input, None)
|
|
|
1 |
import json
|
2 |
|
|
|
3 |
MEMORY_FILE = "memory.json"
|
4 |
|
|
|
5 |
def load_memory():
|
6 |
try:
|
7 |
with open(MEMORY_FILE, "r", encoding="utf-8") as f:
|
|
|
9 |
except FileNotFoundError:
|
10 |
return {}
|
11 |
|
|
|
12 |
def save_memory(memory):
|
13 |
with open(MEMORY_FILE, "w", encoding="utf-8") as f:
|
14 |
json.dump(memory, f, indent=4)
|
15 |
|
|
|
16 |
def update_memory(user_input, bot_response):
|
17 |
memory = load_memory()
|
18 |
memory[user_input] = bot_response
|
19 |
save_memory(memory)
|
20 |
|
|
|
21 |
def check_memory(user_input):
|
22 |
memory = load_memory()
|
23 |
return memory.get(user_input, None)
|