xTwin / config.py
aamirhameed's picture
Update config.py
ebe9d57 verified
import os
import tempfile
from pathlib import Path
class Config:
# Use temporary directories for HF Spaces
BASE_DIR = Path(tempfile.gettempdir()) / "sirraya_xbrain"
# Core directories
KNOWLEDGE_DIR = BASE_DIR / "knowledge"
VECTOR_STORE_PATH = BASE_DIR / "vector_store"
BM25_STORE_PATH = BASE_DIR / "bm25_store.pkl"
# Processing parameters
CHUNK_SIZE = 1000
CHUNK_OVERLAP = 200
MAX_CONTEXT_CHUNKS = 5
# Model settings
EMBEDDING_MODEL = "sentence-transformers/all-mpnet-base-v2"
FALLBACK_EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
# HF Models (in order of preference)
PRIMARY_LLM = "mistralai/Mistral-7B-Instruct-v0.1"
FALLBACK_LLMS = [
"microsoft/DialoGPT-medium",
"google/flan-t5-base",
"huggingface/CodeBERTa-small-v1"
]
# API settings
LLM_TEMPERATURE = 0.1
MAX_NEW_TOKENS = 512
REQUEST_TIMEOUT = 60
@classmethod
def setup_dirs(cls):
"""Setup required directories"""
cls.BASE_DIR.mkdir(parents=True, exist_ok=True)
cls.KNOWLEDGE_DIR.mkdir(parents=True, exist_ok=True)
cls.VECTOR_STORE_PATH.mkdir(parents=True, exist_ok=True)
@classmethod
def get_hf_token(cls):
"""Get HuggingFace API token from environment"""
return os.getenv("HUGGINGFACEHUB_API_TOKEN") or os.getenv("HF_TOKEN")
@classmethod
def cleanup_temp_dirs(cls):
"""Cleanup temporary directories"""
try:
import shutil
if cls.BASE_DIR.exists():
shutil.rmtree(cls.BASE_DIR)
except Exception as e:
print(f"Cleanup error: {e}")
# Environment-specific settings
IS_HF_SPACES = os.getenv("SPACE_ID") is not None
IS_LOCAL = not IS_HF_SPACES