# config.py - Configuración del Space import os class Config: """Configuración centralizada para el Space""" # Modelo MODEL_NAME = "meta-llama/Llama-3.2-3B-Instruct" DEVICE = "cuda" if os.environ.get("SPACES_GPU") else "cpu" # Tokens y autenticación HF_TOKEN = os.environ.get("HF_TOKEN") # Límites de generación MAX_TOKENS_LIMIT = 1024 MIN_TOKENS_LIMIT = 50 DEFAULT_MAX_TOKENS = 512 # Temperatura MAX_TEMPERATURE = 2.0 MIN_TEMPERATURE = 0.1 DEFAULT_TEMPERATURE = 0.7 # Cola y concurrencia MAX_QUEUE_SIZE = 10 QUEUE_TIMEOUT = 300 # 5 minutos # Context length MAX_CONTEXT_LENGTH = 2048 # Interface CHAT_HEIGHT = 500 DEFAULT_SYSTEM_PROMPT = "Eres un asistente de IA útil y amigable. Responde de manera clara y concisa." # API API_TIMEOUT = 300 ENABLE_API_LOGGING = True @classmethod def validate(cls): """Validar configuración""" errors = [] if not cls.HF_TOKEN: errors.append("HF_TOKEN no configurado en variables de entorno") if cls.MAX_TOKENS_LIMIT < cls.MIN_TOKENS_LIMIT: errors.append("MAX_TOKENS_LIMIT debe ser mayor que MIN_TOKENS_LIMIT") if cls.MAX_TEMPERATURE < cls.MIN_TEMPERATURE: errors.append("MAX_TEMPERATURE debe ser mayor que MIN_TEMPERATURE") return errors @classmethod def get_model_config(cls): """Configuración específica del modelo""" return { "torch_dtype": "float16" if cls.DEVICE == "cuda" else "float32", "device_map": "auto" if cls.DEVICE == "cuda" else None, "trust_remote_code": True, "token": cls.HF_TOKEN } @classmethod def get_generation_config(cls, max_tokens=None, temperature=None): """Configuración de generación""" return { "max_new_tokens": max_tokens or cls.DEFAULT_MAX_TOKENS, "temperature": temperature or cls.DEFAULT_TEMPERATURE, "do_sample": True, "repetition_penalty": 1.1, "top_p": 0.9, "top_k": 50 } # Validar configuración al importar config_errors = Config.validate() if config_errors: print("⚠️ Errores de configuración:") for error in config_errors: print(f" - {error}")