Spaces:
Sleeping
Sleeping
Update config.py
Browse files
config.py
CHANGED
|
@@ -1,23 +1,60 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import tempfile
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
class Config:
|
| 6 |
+
# Use temporary directories for HF Spaces
|
| 7 |
+
BASE_DIR = Path(tempfile.gettempdir()) / "sirraya_xbrain"
|
| 8 |
+
|
| 9 |
+
# Core directories
|
| 10 |
+
KNOWLEDGE_DIR = BASE_DIR / "knowledge"
|
| 11 |
+
VECTOR_STORE_PATH = BASE_DIR / "vector_store"
|
| 12 |
+
BM25_STORE_PATH = BASE_DIR / "bm25_store.pkl"
|
| 13 |
+
|
| 14 |
+
# Processing parameters
|
| 15 |
+
CHUNK_SIZE = 1000
|
| 16 |
+
CHUNK_OVERLAP = 200
|
| 17 |
+
MAX_CONTEXT_CHUNKS = 5
|
| 18 |
+
|
| 19 |
+
# Model settings
|
| 20 |
+
EMBEDDING_MODEL = "sentence-transformers/all-mpnet-base-v2"
|
| 21 |
+
FALLBACK_EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
|
| 22 |
+
|
| 23 |
+
# HF Models (in order of preference)
|
| 24 |
+
PRIMARY_LLM = "mistralai/Mistral-7B-Instruct-v0.1"
|
| 25 |
+
FALLBACK_LLMS = [
|
| 26 |
+
"microsoft/DialoGPT-medium",
|
| 27 |
+
"google/flan-t5-base",
|
| 28 |
+
"huggingface/CodeBERTa-small-v1"
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
# API settings
|
| 32 |
+
LLM_TEMPERATURE = 0.1
|
| 33 |
+
MAX_NEW_TOKENS = 512
|
| 34 |
+
REQUEST_TIMEOUT = 60
|
| 35 |
+
|
| 36 |
+
@classmethod
|
| 37 |
+
def setup_dirs(cls):
|
| 38 |
+
"""Setup required directories"""
|
| 39 |
+
cls.BASE_DIR.mkdir(parents=True, exist_ok=True)
|
| 40 |
+
cls.KNOWLEDGE_DIR.mkdir(parents=True, exist_ok=True)
|
| 41 |
+
cls.VECTOR_STORE_PATH.mkdir(parents=True, exist_ok=True)
|
| 42 |
+
|
| 43 |
+
@classmethod
|
| 44 |
+
def get_hf_token(cls):
|
| 45 |
+
"""Get HuggingFace API token from environment"""
|
| 46 |
+
return os.getenv("HUGGINGFACEHUB_API_TOKEN") or os.getenv("HF_TOKEN")
|
| 47 |
+
|
| 48 |
+
@classmethod
|
| 49 |
+
def cleanup_temp_dirs(cls):
|
| 50 |
+
"""Cleanup temporary directories"""
|
| 51 |
+
try:
|
| 52 |
+
import shutil
|
| 53 |
+
if cls.BASE_DIR.exists():
|
| 54 |
+
shutil.rmtree(cls.BASE_DIR)
|
| 55 |
+
except Exception as e:
|
| 56 |
+
print(f"Cleanup error: {e}")
|
| 57 |
+
|
| 58 |
+
# Environment-specific settings
|
| 59 |
+
IS_HF_SPACES = os.getenv("SPACE_ID") is not None
|
| 60 |
+
IS_LOCAL = not IS_HF_SPACES
|