From 67e214db154465e82b05ab8f60e4b8f876f01d09 Mon Sep 17 00:00:00 2001 From: consultoria-as Date: Thu, 2 Apr 2026 08:02:10 +0000 Subject: [PATCH] =?UTF-8?q?fix(pos):=20bloquear=20modelos=20de=20pago=20?= =?UTF-8?q?=E2=80=94=20solo=20modelos=20:free=20permitidos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Validacion _validate_model() verifica que el modelo termine en ':free'. Si alguien cambia MODEL a uno de pago, el chatbot lanza error en vez de generar costos. Alternativas documentadas en comentario. Co-Authored-By: Claude Opus 4.6 (1M context) --- pos/services/ai_chat.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pos/services/ai_chat.py b/pos/services/ai_chat.py index d7cbd52..65aa86e 100644 --- a/pos/services/ai_chat.py +++ b/pos/services/ai_chat.py @@ -6,7 +6,16 @@ import json from config import OPENROUTER_API_KEY OPENROUTER_URL = "https://openrouter.ai/api/v1/chat/completions" -MODEL = "qwen/qwen3-6b-preview:free" # Qwen 3.6 Plus Preview (free on OpenRouter) + +# ⚠️ SOLO MODELOS GRATUITOS — No cambiar a modelos de pago. +# El modelo DEBE terminar en ":free" para garantizar costo $0. +# Alternativas gratuitas: "meta-llama/llama-4-scout:free", "google/gemma-3-27b-it:free" +MODEL = "qwen/qwen3-6b-preview:free" + +def _validate_model(model_id): + """Ensure only free models are used. Raises if model is not free.""" + if not model_id.endswith(':free'): + raise ValueError(f"BLOQUEADO: Solo se permiten modelos gratuitos (:free). Modelo '{model_id}' no es gratuito.") SYSTEM_PROMPT = """Eres un asistente de refaccionaria automotriz mexicana. Tu trabajo es ayudar a encontrar autopartes. @@ -45,6 +54,7 @@ Reglas OBLIGATORIAS: def chat(user_message, conversation_history=None): """Send a message to the AI and get a response with search suggestions.""" + _validate_model(MODEL) # Block paid models messages = [{"role": "system", "content": SYSTEM_PROMPT}] if conversation_history: messages.extend(conversation_history)