Spaces:
Running
Running
EMMA commited on
Commit ·
a39f3d3
1
Parent(s): dfbf298
update code
Browse files- memory_bank/summarize_memory.py +11 -33
memory_bank/summarize_memory.py
CHANGED
|
@@ -347,38 +347,7 @@ CRITICAL INSTRUCTIONS:
|
|
| 347 |
return updated_semantic_memory
|
| 348 |
|
| 349 |
|
| 350 |
-
updated_semantic_memory = existing_semantic_memory if isinstance(existing_semantic_memory, dict) else {}
|
| 351 |
-
|
| 352 |
|
| 353 |
-
for trait, value in new_semantic_data.get("personality_traits", {}).items():
|
| 354 |
-
try:
|
| 355 |
-
val_float = float(value)
|
| 356 |
-
except (ValueError, TypeError):
|
| 357 |
-
val_float = 0.0
|
| 358 |
-
|
| 359 |
-
if trait in updated_semantic_memory.get("personality_traits", {}):
|
| 360 |
-
existing_value = float(updated_semantic_memory["personality_traits"].get(trait, 0.0))
|
| 361 |
-
updated_semantic_memory["personality_traits"][trait] = round((existing_value + val_float) / 2, 2)
|
| 362 |
-
else:
|
| 363 |
-
updated_semantic_memory.setdefault("personality_traits", {})[trait] = val_float
|
| 364 |
-
|
| 365 |
-
# Combine core values, avoiding duplicates
|
| 366 |
-
updated_semantic_memory["core_values"] = list(set(
|
| 367 |
-
updated_semantic_memory.get("core_values", []) + new_semantic_data.get("core_values", [])
|
| 368 |
-
))
|
| 369 |
-
|
| 370 |
-
# Combine behavioral patterns
|
| 371 |
-
updated_semantic_memory["behavioral_patterns"] = list(set(
|
| 372 |
-
updated_semantic_memory.get("behavioral_patterns", []) + new_semantic_data.get("behavioral_patterns", [])
|
| 373 |
-
))
|
| 374 |
-
|
| 375 |
-
# Combine recurring themes
|
| 376 |
-
updated_semantic_memory["recurring_themes"] = list(set(
|
| 377 |
-
updated_semantic_memory.get("recurring_themes", []) + new_semantic_data.get("recurring_themes", [])
|
| 378 |
-
))
|
| 379 |
-
|
| 380 |
-
print("\n✅ Semantic memory updated successfully!")
|
| 381 |
-
return updated_semantic_memory
|
| 382 |
|
| 383 |
|
| 384 |
|
|
@@ -387,8 +356,17 @@ def summarize_memory(memory_dir, name=None, language='en'):
|
|
| 387 |
boot_name = 'AI'
|
| 388 |
gen_prompt_num = 1
|
| 389 |
|
| 390 |
-
|
| 391 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
|
| 393 |
for k, v in memory.items():
|
| 394 |
if name is not None and k != name:
|
|
|
|
| 347 |
return updated_semantic_memory
|
| 348 |
|
| 349 |
|
|
|
|
|
|
|
| 350 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
|
| 352 |
|
| 353 |
|
|
|
|
| 356 |
boot_name = 'AI'
|
| 357 |
gen_prompt_num = 1
|
| 358 |
|
| 359 |
+
# بررسی وجود فایل قبل از خواندن آن
|
| 360 |
+
if not os.path.exists(memory_dir):
|
| 361 |
+
print(f"[INFO] Memory file not found at {memory_dir}. Initializing empty memory.")
|
| 362 |
+
memory = {}
|
| 363 |
+
else:
|
| 364 |
+
with open(memory_dir, 'r', encoding='utf8') as f:
|
| 365 |
+
try:
|
| 366 |
+
memory = json.loads(f.read())
|
| 367 |
+
except json.JSONDecodeError:
|
| 368 |
+
print("[WARNING] Memory file is empty or corrupted. Initializing empty memory.")
|
| 369 |
+
memory = {}
|
| 370 |
|
| 371 |
for k, v in memory.items():
|
| 372 |
if name is not None and k != name:
|