Feat: Agregar agente Groq con integración RAG
- Nuevo módulo groq_agent.py para consultas a la API de Groq - Panel de administración en /groq para configurar API key, modelo y prompt - Comando /rag en Discord y Telegram para consultar el RAG - Sistema de prompt personalizable guardado en base de datos - Soporte para variables de entorno en Docker - Fix: starlette version para evitar bug con Jinja2
This commit is contained in:
@@ -291,6 +291,33 @@ async def handle_sticker(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
async def handle_video_note(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
return
|
||||
|
||||
async def rag_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
if not context.args:
|
||||
await update.message.reply_text(
|
||||
"Uso: /rag <pregunta>\n\n"
|
||||
"Ejemplo: /rag How to get heroes?"
|
||||
)
|
||||
return
|
||||
|
||||
pregunta = " ".join(context.args)
|
||||
await update.message.reply_text("🔍 Buscando en la base de conocimientos...")
|
||||
|
||||
from botdiscord.groq_agent import chat_with_rag
|
||||
result = await chat_with_rag(pregunta)
|
||||
|
||||
response = result.get("response", "Sin respuesta")
|
||||
sources = result.get("sources", [])
|
||||
|
||||
text = f"🔍 *Last War Knowledge*\n\n{response}"
|
||||
|
||||
if sources:
|
||||
text += "\n\n*Fuentes:*\n"
|
||||
for s in sources[:3]:
|
||||
title = s.get("title", "N/A")
|
||||
text += f"• {title}\n"
|
||||
|
||||
await update.message.reply_text(text, parse_mode="Markdown")
|
||||
|
||||
def run_telegram_bot():
|
||||
try:
|
||||
from botdiscord.database import init_db
|
||||
@@ -323,6 +350,7 @@ def run_telegram_bot():
|
||||
|
||||
application.add_handler(CommandHandler("start", start))
|
||||
application.add_handler(CommandHandler("idiomas", languages_command))
|
||||
application.add_handler(CommandHandler("rag", rag_command))
|
||||
application.add_handler(CallbackQueryHandler(translation_callback, pattern="^trans_"))
|
||||
application.add_handler(MessageHandler(filters.PHOTO, handle_photo))
|
||||
application.add_handler(MessageHandler(filters.Document.ALL, handle_document))
|
||||
|
||||
Reference in New Issue
Block a user