Skip to content

Nuevo Asistente Nutricional con IA#22

Merged
ComputingVictor merged 13 commits intomainfrom
dev
Nov 1, 2025
Merged

Nuevo Asistente Nutricional con IA#22
ComputingVictor merged 13 commits intomainfrom
dev

Conversation

@ComputingVictor
Copy link
Copy Markdown
Owner

🤖 Nuevo Asistente Nutricional con IA

Este PR añade un chat inteligente con IA que ayuda a los usuarios a planificar sus dietas usando exclusivamente productos de Mercadona.


✨ Características Principales

💬 Chat Inteligente

  • Asistente nutricional especializado en dietas: volumen, definición, mantenimiento, etc.
  • Integración con OpenRouter API usando GitHub Secrets
  • Modo DEMO cuando no hay API key configurada
  • Interfaz responsive optimizada para móvil y escritorio

🔗 Enlaces a Productos

  • Los productos mencionados en el chat son enlaces clicables
  • Al hacer click, se cierra el chat y se abre el modal del producto
  • Detección inteligente de nombres de productos en las respuestas

🔒 Seguridad

  • API key gestionada mediante GitHub Secrets
  • NO se expone la API key en el código fuente
  • Deployment automático con GitHub Actions
  • config.js generado automáticamente en cada deploy

🎯 Prompt Estricto

  • SOLO recomienda productos de la base de datos de Mercadona
  • NO inventa productos ni precios
  • Incluye 200 productos en el contexto del LLM
  • Ejemplos explícitos de respuestas correctas e incorrectas

🗂️ Archivos Nuevos

  • chat.js - Lógica del asistente de chat
  • chat.css - Estilos responsive del chat
  • config-secure.js - Sistema de configuración segura
  • .github/workflows/deploy.yml - Workflow de deployment automático

📝 Archivos Modificados

  • index.html - Añadido botón flotante y container del chat
  • script.js - Integración del chat en la app principal
  • style.css - Ajustes de estilos
  • .gitignore - Ignorar config.js local

🚀 Cómo Funciona

Para Desarrollo Local

  1. Edita config.js y añade tu API key
  2. El archivo está en .gitignore (no se sube a GitHub)
  3. El chat funciona con tu API key local

Para Producción (GitHub Pages)

  1. Configura secrets en: Settings > Secrets and variables > Actions
    • OPENROUTER_API_KEY: Tu API key de OpenRouter
    • CHAT_MODEL: Modelo a usar (ej: deepseek/deepseek-chat)
  2. GitHub Actions ejecuta el workflow
  3. Se crea config.js automáticamente con los secrets
  4. Se despliega a GitHub Pages
  5. El chat funciona automáticamente

🎨 Interfaz

  • Botón flotante con icono de pesa 💪 (esquina inferior derecha)
  • Chat desplegable con animaciones suaves
  • Temas claro/oscuro integrados
  • Enlaces de productos con hover effects
  • Historial persistente en localStorage

📊 Commits Incluidos

  • 055795f - feat: Strengthen system prompt to ONLY use products from database
  • f4f6388 - feat: Implementar modo DEMO en el chat
  • 139405b - fix: Configure workflow to deploy only from dev branch
  • 2ea772c - fix: Always show chat button, add warning badge if no API key
  • 69c2b5e - feat: Add clickable product links in chat messages
  • ffae312 - fix: Enable workflow on dev branch
  • 60cde02 - feat: Transform chat into nutrition assistant with diet planning
  • 5e8e619 - feat: Añadir configuración de despliegue en GitHub Pages con secretos de GitHub
  • 0a5d135 - feat: Implement Recipe Assistant Chat with OpenRouter API integration

✅ Testing

  • Chat funciona con API key válida
  • Modo DEMO funciona sin API key
  • Enlaces de productos abren modales correctamente
  • Responsive en móvil y escritorio
  • Prompt respeta base de datos de productos
  • GitHub Actions despliega correctamente
  • Secrets se inyectan en config.js

🔧 Configuración Requerida

Antes de mergear, asegúrate de:

  1. GitHub Pages configurado a "GitHub Actions"

    • Settings > Pages > Source > GitHub Actions
  2. Secrets configurados

    • Settings > Secrets and variables > Actions
    • Añadir OPENROUTER_API_KEY
    • Añadir CHAT_MODEL (opcional)

💰 Costos

OpenRouter tiene modelos gratuitos:

  • meta-llama/llama-3.1-70b-instruct (gratis)
  • google/gemini-flash-1.5 (gratis con límites)

También soporta modelos de pago como Claude, GPT-4, etc.


📚 Documentación

Todo está documentado en el código con comentarios JSDoc.


Ready to merge! 🎉

- Introduced a new state for showing discounts in the MercadonaApp.
- Implemented functionality to filter and display discounted products.
- Added event listeners for the new discounts button in the UI.
- Updated product card to show discount badges and adjusted price display.
- Enhanced UI with new styles for discount badges and buttons.
- Updated mobile menu to include discounts option and styling.
- Added utility functions to manage discounts display and counts.
- Added chat UI styles in chat.css for a floating action button, chat container, header, messages area, and input area.
- Developed chat functionality in chat.js, including message handling, AI response fetching, and chat history management.
- Created a secure configuration system in config-secure.js to manage API keys and chat model preferences without exposing sensitive information.
- Added a setup script (setup-chat.sh) for easy configuration and local server setup.
- Changed from recipe assistant to nutrition/diet planning assistant
- Updated system prompt to focus on diets (bulk, cut, maintenance, etc.)
- Simplified to use only GitHub Secrets API key (no localStorage)
- Updated UI labels and icons (chef -> dumbbell)
- Ready to use with MiniMax M2 model from secrets
- Users can now get diet recommendations based on fitness goals
- Products mentioned in chat are now automatically converted to clickable links
- Clicking a product link closes the chat and opens the product detail modal
- Added CSS styling for product links with hover effects
- Links work for both user and assistant messages
- Intelligent matching: longest product names matched first to avoid partial matches
- Chat button now always visible (not hidden)
- Shows yellow warning badge (!) if API key not configured
- Clicking without API key shows helpful message
- Better UX for both local development and production
- Added clear warning that ONLY products in the database can be mentioned
- Increased product list from 150 to 200 items for better coverage
- Added explicit examples of correct vs incorrect responses
- Emphasized that products NOT in the list DO NOT EXIST
- Added rule to suggest alternatives when exact product not found
- More emojis for visual emphasis (✅❌⚠️)
- Clearer structure with REGLAS ESTRICTAS section
@ComputingVictor ComputingVictor self-assigned this Nov 1, 2025
@ComputingVictor ComputingVictor added the enhancement New feature or request label Nov 1, 2025
@ComputingVictor ComputingVictor merged commit 409be1b into main Nov 1, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant