Spaces:
Sleeping
Sleeping
EMMA commited on
Commit ·
e7afd00
1
Parent(s): a39f3d3
update code
Browse files- utils/memory_utils.py +28 -10
utils/memory_utils.py
CHANGED
|
@@ -11,12 +11,12 @@ import traceback
|
|
| 11 |
# LlamaIndex Imports
|
| 12 |
from llama_index.core import StorageContext, load_index_from_storage, VectorStoreIndex
|
| 13 |
|
| 14 |
-
|
| 15 |
# Local Imports setup
|
| 16 |
# Assuming this file is in 'utils/', we step back to find 'memory_bank'
|
| 17 |
CURRENT_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 18 |
-
BASE_DIR
|
| 19 |
-
|
|
|
|
| 20 |
sys.path.append(bank_path)
|
| 21 |
|
| 22 |
# Import functions from sibling/child modules
|
|
@@ -33,15 +33,33 @@ except ImportError:
|
|
| 33 |
def extract_semantic_memory(*args, **kwargs): return {}
|
| 34 |
|
| 35 |
|
| 36 |
-
# یکپارچهسازی و استانداردسازی مسیرها (منطبق با پیکربندی مصوب)
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
|
|
|
| 41 |
|
| 42 |
# مسیر فایل json
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
def enter_name(name, memory, local_memory_qa, data_args, update_memory_index=True):
|
|
@@ -272,4 +290,4 @@ def save_local_memory(memory, history, user_name, data_args, new_conversation=Fa
|
|
| 272 |
with open(memory_dir, "w", encoding="utf-8") as f:
|
| 273 |
json.dump(memory, f, ensure_ascii=False, indent=4)
|
| 274 |
|
| 275 |
-
return memory, semantic_memory_text
|
|
|
|
| 11 |
# LlamaIndex Imports
|
| 12 |
from llama_index.core import StorageContext, load_index_from_storage, VectorStoreIndex
|
| 13 |
|
|
|
|
| 14 |
# Local Imports setup
|
| 15 |
# Assuming this file is in 'utils/', we step back to find 'memory_bank'
|
| 16 |
CURRENT_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 17 |
+
# تغییر نام BASE_DIR در اینجا برای جلوگیری از تداخل با BASE_DIR مسیرهای پایین
|
| 18 |
+
APP_ROOT_DIR = os.path.abspath(os.path.join(CURRENT_SCRIPT_DIR, ".."))
|
| 19 |
+
bank_path = os.path.join(APP_ROOT_DIR, 'memory_bank')
|
| 20 |
sys.path.append(bank_path)
|
| 21 |
|
| 22 |
# Import functions from sibling/child modules
|
|
|
|
| 33 |
def extract_semantic_memory(*args, **kwargs): return {}
|
| 34 |
|
| 35 |
|
| 36 |
+
# --- یکپارچهسازی و استانداردسازی مسیرها (منطبق با پیکربندی مصوب جدید) ---
|
| 37 |
+
REPO_ID = "Keyvan1986/Emma-memory-storage"
|
| 38 |
+
REPO_TYPE = "dataset"
|
| 39 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 40 |
+
|
| 41 |
+
# مسیرهای اصلی (Absolute Paths) برای جلوگیری از ساخته شدن پوشه در مسیرهای اشتباه
|
| 42 |
+
BASE_DIR = os.path.abspath(os.getcwd()) # معمولاً /app
|
| 43 |
+
MEMORIES_DIR = os.path.join(BASE_DIR, "memories")
|
| 44 |
+
MEMORY_INDEX_DIR_NAME = "memory_index"
|
| 45 |
+
MEMORY_INDEX_PATH = os.path.join(MEMORIES_DIR, MEMORY_INDEX_DIR_NAME)
|
| 46 |
|
| 47 |
+
_LLAMAINDEX_BASE_DIR = os.path.join(MEMORY_INDEX_PATH, "llamaindex")
|
| 48 |
|
| 49 |
# مسیر فایل json
|
| 50 |
+
MEMORY_FILE_NAME = "update_memory_0512_eng.json"
|
| 51 |
+
MEMORY_FILE_PATH = os.path.join(MEMORIES_DIR, MEMORY_FILE_NAME)
|
| 52 |
+
|
| 53 |
+
# اطمینان از وجود پوشهها
|
| 54 |
+
os.makedirs(MEMORIES_DIR, exist_ok=True)
|
| 55 |
+
os.makedirs(MEMORY_INDEX_PATH, exist_ok=True)
|
| 56 |
+
os.makedirs(_LLAMAINDEX_BASE_DIR, exist_ok=True)
|
| 57 |
+
|
| 58 |
+
print(f"📂 Path Configuration:")
|
| 59 |
+
print(f" - App Base Dir: {BASE_DIR}")
|
| 60 |
+
print(f" - Memories Dir: {MEMORIES_DIR}")
|
| 61 |
+
print(f" - Memory Index Path: {MEMORY_INDEX_PATH}")
|
| 62 |
+
# ------------------------------------------------------------------------
|
| 63 |
|
| 64 |
|
| 65 |
def enter_name(name, memory, local_memory_qa, data_args, update_memory_index=True):
|
|
|
|
| 290 |
with open(memory_dir, "w", encoding="utf-8") as f:
|
| 291 |
json.dump(memory, f, ensure_ascii=False, indent=4)
|
| 292 |
|
| 293 |
+
return memory, semantic_memory_text
|