doky-opus / config.py
oriolgds's picture
Testing completely new code
b0e9cd9 unverified
# 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}")