""" Global Configuration for the Conversational Intelligence System. Centralizes all paths, hyperparameters, and model settings. """ import os from pathlib import Path # ────────────────────────────────────────────────────────────── # PATHS # ────────────────────────────────────────────────────────────── BASE_DIR = Path(__file__).parent.resolve() DATA_DIR = BASE_DIR / "data" MODEL_DIR = BASE_DIR / "models" REPORT_DIR = BASE_DIR / "reports" VECTOR_DB_DIR = BASE_DIR / "vector_store" LOG_DIR = BASE_DIR / "logs" # Create directories for d in [DATA_DIR, MODEL_DIR, REPORT_DIR, VECTOR_DB_DIR, LOG_DIR]: d.mkdir(parents=True, exist_ok=True) # ────────────────────────────────────────────────────────────── # DATASET # ────────────────────────────────────────────────────────────── DATASET_NAME = "ag_news" NUM_CLASSES = 4 CLASS_NAMES = ["World", "Sports", "Business", "Sci/Tech"] MAX_SAMPLES_TRAIN = 200 # Small sample for fast automatic demo MAX_SAMPLES_TEST = 50 # ────────────────────────────────────────────────────────────── # MODEL CONFIGURATIONS # ────────────────────────────────────────────────────────────── MODELS = { "bert": { "name": "bert-base-uncased", "architecture": "Bidirectional Transformer Encoder", "description": "Reads text in both directions simultaneously for strong contextual understanding", "max_length": 128, "batch_size": 16, "learning_rate": 2e-5, "epochs": 3, "weight_decay": 0.01, }, "gpt2": { "name": "gpt2", "architecture": "Autoregressive Transformer Decoder", "description": "Token-by-token text generation with causal attention mechanism", "max_length": 128, "batch_size": 8, "learning_rate": 5e-5, "epochs": 1, "weight_decay": 0.01, }, "llama": { "name": "TinyLlama/TinyLlama-1.1B-Chat-v1.0", "architecture": "Decoder-based Large Language Model", "description": "Efficient transformer architecture with strong reasoning ability", "max_length": 128, "batch_size": 4, "learning_rate": 2e-5, "epochs": 1, "weight_decay": 0.01, "use_lora": True, "lora_r": 8, "lora_alpha": 16, "lora_dropout": 0.1, }, "mistral": { "name": "mistralai/Mistral-7B-v0.1", "architecture": "Transformer with Sliding Window Attention", "description": "Efficient long-context processing with fast inference", "max_length": 128, "batch_size": 2, "learning_rate": 2e-5, "epochs": 1, "weight_decay": 0.01, "use_lora": True, "lora_r": 8, "lora_alpha": 16, "lora_dropout": 0.1, "local_training": False, }, "xlnet": { "name": "xlnet-base-cased", "architecture": "Permutation-based Autoregressive Transformer", "description": "Combines autoregressive and bidirectional modeling for improved contextual understanding", "max_length": 128, "batch_size": 16, "learning_rate": 2e-5, "epochs": 1, "weight_decay": 0.01, }, } # ────────────────────────────────────────────────────────────── # EMBEDDING / RAG # ────────────────────────────────────────────────────────────── EMBEDDING_MODEL = "all-MiniLM-L6-v2" CHROMA_COLLECTION = "project_knowledge" CHUNK_SIZE = 500 CHUNK_OVERLAP = 50 TOP_K_RESULTS = 5 # ────────────────────────────────────────────────────────────── # CONVERSATIONAL AI # ────────────────────────────────────────────────────────────── GROQ_MODEL = "llama-3.1-8b-instant" MAX_RESPONSE_TOKENS = 1000 TEMPERATURE = 0.3 # ────────────────────────────────────────────────────────────── # SERVER # ────────────────────────────────────────────────────────────── HOST = os.environ.get("HOST", "0.0.0.0") PORT = int(os.environ.get("PORT", "8509")) DEBUG = True # Model Download from HF Hub import shutil import logging logger = logging.getLogger(__name__) def download_models_if_needed(): """Download models from Neerajkadari/my_project_models if not present locally.""" from huggingface_hub import snapshot_download models_needed = ["bert", "gpt2", "llama", "xlnet"] any_missing = any( not (MODEL_DIR / m).exists() for m in models_needed ) if any_missing: logger.info("Downloading models from Neerajkadari/my_project_models...") local_path = snapshot_download( repo_id="Neerajkadari/my_project_models", repo_type="model", local_dir=str(BASE_DIR / "downloaded_models"), force_download=True ) # Move models into expected location src = Path(local_path) / "models" for model_name in models_needed: src_model = src / model_name dst_model = MODEL_DIR / model_name if src_model.exists() and not dst_model.exists(): shutil.copytree(str(src_model), str(dst_model)) logger.info(f"Model '{model_name}' placed at {dst_model}") elif dst_model.exists(): logger.info(f"Model '{model_name}' already exists at {dst_model}") logger.info("Model download complete!") # Auto-download models on import if not any((MODEL_DIR / m).exists() for m in ["bert", "gpt2", "llama", "xlnet"]): download_models_if_needed()