Spaces:
Sleeping
Sleeping
EMMA commited on
Commit ·
dfbf298
1
Parent(s): 7e8bf6e
update code
Browse files- memory_bank/summarize_memory.py +23 -11
- utils/memory_utils.py +2 -1
memory_bank/summarize_memory.py
CHANGED
|
@@ -31,7 +31,8 @@ if os.path.exists("/data"):
|
|
| 31 |
else:
|
| 32 |
BASE_DATA_DIR = os.environ.get("EMMA_DATA_DIR", PROJECT_ROOT)
|
| 33 |
|
| 34 |
-
MEMORY_DIR = os.path.join(BASE_DATA_DIR, "
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
class LLMClientSimple:
|
|
@@ -199,16 +200,19 @@ def extract_session_summary(conversation_text, session_date, session_id):
|
|
| 199 |
"""
|
| 200 |
# Prompt to the LLM to extract insights
|
| 201 |
insight_prompt = f"""
|
| 202 |
-
Please analyze the following conversation and extract key information
|
| 203 |
|
| 204 |
Conversation:
|
| 205 |
{conversation_text}
|
| 206 |
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
-
Format response as JSON:
|
| 212 |
{{
|
| 213 |
"topics_discussed": [],
|
| 214 |
"emotional_state": "",
|
|
@@ -259,9 +263,16 @@ def extract_semantic_memory(latest_episodic_memory, existing_semantic_memory):
|
|
| 259 |
"""
|
| 260 |
# Use the insights from episodic memory to infer stable traits and patterns
|
| 261 |
semantic_prompt = f"""
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
Update the user's semantic memory with:
|
| 267 |
1. Evolving personality traits (Big Five).
|
|
@@ -269,7 +280,7 @@ def extract_semantic_memory(latest_episodic_memory, existing_semantic_memory):
|
|
| 269 |
3. Behavioral patterns and consistent emotional responses.
|
| 270 |
4. Frequent topics and recurring themes.
|
| 271 |
|
| 272 |
-
Format response as JSON:
|
| 273 |
{{
|
| 274 |
"personality_traits": {{
|
| 275 |
"openness": 0.0,
|
|
@@ -437,7 +448,8 @@ def summarize_memory(memory_dir, name=None, language='en'):
|
|
| 437 |
if __name__ == '__main__':
|
| 438 |
# مسیردهی هوشمند برای محیط ابری
|
| 439 |
base_dir = "/data" if os.path.exists("/data") else os.environ.get("EMMA_DATA_DIR", PROJECT_ROOT)
|
| 440 |
-
target_memory = os.path.join(base_dir, '
|
|
|
|
| 441 |
|
| 442 |
if os.path.exists(target_memory):
|
| 443 |
summarize_memory(target_memory, language='en')
|
|
|
|
| 31 |
else:
|
| 32 |
BASE_DATA_DIR = os.environ.get("EMMA_DATA_DIR", PROJECT_ROOT)
|
| 33 |
|
| 34 |
+
MEMORY_DIR = os.path.join(BASE_DATA_DIR, "Emma-memory-storage", "update_memory_0512_eng.json")
|
| 35 |
+
|
| 36 |
|
| 37 |
|
| 38 |
class LLMClientSimple:
|
|
|
|
| 200 |
"""
|
| 201 |
# Prompt to the LLM to extract insights
|
| 202 |
insight_prompt = f"""
|
| 203 |
+
Please analyze the following conversation and extract key information.
|
| 204 |
|
| 205 |
Conversation:
|
| 206 |
{conversation_text}
|
| 207 |
|
| 208 |
+
CRITICAL INSTRUCTIONS:
|
| 209 |
+
1. You MUST output ONLY a valid JSON object.
|
| 210 |
+
2. DO NOT include any conversational text, greetings, or explanations (e.g., do not say "Sure!").
|
| 211 |
+
3. DO NOT include markdown formatting like
|
| 212 |
+
```json.
|
| 213 |
+
4. DO NOT include any comments (like //) inside the JSON.
|
| 214 |
|
| 215 |
+
Format response EXACTLY as this JSON structure:
|
| 216 |
{{
|
| 217 |
"topics_discussed": [],
|
| 218 |
"emotional_state": "",
|
|
|
|
| 263 |
"""
|
| 264 |
# Use the insights from episodic memory to infer stable traits and patterns
|
| 265 |
semantic_prompt = f"""
|
| 266 |
+
Please analyze the following session summary and infer long-term personality traits and stable characteristics:
|
| 267 |
+
Session Summary:
|
| 268 |
+
{json.dumps(latest_episodic_memory, indent=4)}
|
| 269 |
+
|
| 270 |
+
CRITICAL INSTRUCTIONS:
|
| 271 |
+
1. You MUST output ONLY a valid JSON object.
|
| 272 |
+
2. DO NOT include any conversational text, greetings, or explanations.
|
| 273 |
+
3. DO NOT include markdown formatting like
|
| 274 |
+
```json.
|
| 275 |
+
4. DO NOT include any comments inside the JSON.
|
| 276 |
|
| 277 |
Update the user's semantic memory with:
|
| 278 |
1. Evolving personality traits (Big Five).
|
|
|
|
| 280 |
3. Behavioral patterns and consistent emotional responses.
|
| 281 |
4. Frequent topics and recurring themes.
|
| 282 |
|
| 283 |
+
Format response EXACTLY as this JSON structure:
|
| 284 |
{{
|
| 285 |
"personality_traits": {{
|
| 286 |
"openness": 0.0,
|
|
|
|
| 448 |
if __name__ == '__main__':
|
| 449 |
# مسیردهی هوشمند برای محیط ابری
|
| 450 |
base_dir = "/data" if os.path.exists("/data") else os.environ.get("EMMA_DATA_DIR", PROJECT_ROOT)
|
| 451 |
+
target_memory = os.path.join(base_dir, 'Emma-memory-storage', 'eng_memory_cases.json')
|
| 452 |
+
|
| 453 |
|
| 454 |
if os.path.exists(target_memory):
|
| 455 |
summarize_memory(target_memory, language='en')
|
utils/memory_utils.py
CHANGED
|
@@ -34,10 +34,11 @@ except ImportError:
|
|
| 34 |
|
| 35 |
|
| 36 |
# یکپارچهسازی و استانداردسازی مسیرها (منطبق با پیکربندی مصوب)
|
| 37 |
-
MEMORIES_DIR = os.path.join(BASE_DIR, "
|
| 38 |
INDEX_BASE_DIR = os.path.join(MEMORIES_DIR, "memory_index")
|
| 39 |
_LLAMAINDEX_BASE_DIR = os.path.join(INDEX_BASE_DIR, "llamaindex")
|
| 40 |
|
|
|
|
| 41 |
# مسیر فایل json
|
| 42 |
MEMORY_FILE_PATH = os.path.join(
|
| 43 |
MEMORIES_DIR, "update_memory_0512_eng.json")
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
# یکپارچهسازی و استانداردسازی مسیرها (منطبق با پیکربندی مصوب)
|
| 37 |
+
MEMORIES_DIR = os.path.join(BASE_DIR, "Emma-memory-storage") # تغییر کلمه memories به Emma-memory-storage
|
| 38 |
INDEX_BASE_DIR = os.path.join(MEMORIES_DIR, "memory_index")
|
| 39 |
_LLAMAINDEX_BASE_DIR = os.path.join(INDEX_BASE_DIR, "llamaindex")
|
| 40 |
|
| 41 |
+
|
| 42 |
# مسیر فایل json
|
| 43 |
MEMORY_FILE_PATH = os.path.join(
|
| 44 |
MEMORIES_DIR, "update_memory_0512_eng.json")
|