Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ from telegram import Update
|
|
| 5 |
from telegram.ext import ApplicationBuilder, ContextTypes, MessageHandler, filters
|
| 6 |
from groq import Groq
|
| 7 |
|
| 8 |
-
# Configuraci贸n de errores para ver qu茅 pasa
|
| 9 |
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
| 10 |
|
| 11 |
TOKEN = os.environ.get("TELEGRAM_TOKEN")
|
|
@@ -14,25 +13,30 @@ GROQ_KEY = os.environ.get("GROQ_API_KEY")
|
|
| 14 |
client = Groq(api_key=GROQ_KEY)
|
| 15 |
|
| 16 |
async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
|
|
|
|
|
|
|
|
| 17 |
try:
|
| 18 |
-
user_text = update.message.text
|
| 19 |
completion = client.chat.completions.create(
|
| 20 |
model="llama3-8b-8192",
|
| 21 |
messages=[
|
| 22 |
-
{"role": "system", "content": "Eres un asistente de cocreaci贸n para el proyecto Argosa.
|
| 23 |
{"role": "user", "content": user_text}
|
| 24 |
]
|
| 25 |
)
|
| 26 |
-
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
if __name__ == '__main__':
|
| 32 |
if not TOKEN or not GROQ_KEY:
|
| 33 |
-
print("Faltan las llaves en Settings
|
| 34 |
else:
|
| 35 |
app = ApplicationBuilder().token(TOKEN).build()
|
| 36 |
app.add_handler(MessageHandler(filters.TEXT & (~filters.COMMAND), handle_message))
|
| 37 |
print("隆Bot despertando!")
|
| 38 |
app.run_polling()
|
|
|
|
|
|
| 5 |
from telegram.ext import ApplicationBuilder, ContextTypes, MessageHandler, filters
|
| 6 |
from groq import Groq
|
| 7 |
|
|
|
|
| 8 |
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
| 9 |
|
| 10 |
TOKEN = os.environ.get("TELEGRAM_TOKEN")
|
|
|
|
| 13 |
client = Groq(api_key=GROQ_KEY)
|
| 14 |
|
| 15 |
async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 16 |
+
user_text = update.message.text
|
| 17 |
+
print(f"Mensaje recibido: {user_text}") # Esto aparecer谩 en los logs
|
| 18 |
+
|
| 19 |
try:
|
|
|
|
| 20 |
completion = client.chat.completions.create(
|
| 21 |
model="llama3-8b-8192",
|
| 22 |
messages=[
|
| 23 |
+
{"role": "system", "content": "Eres un asistente de cocreaci贸n para el proyecto Argosa."},
|
| 24 |
{"role": "user", "content": user_text}
|
| 25 |
]
|
| 26 |
)
|
| 27 |
+
respuesta = completion.choices[0].message.content
|
| 28 |
+
await update.message.reply_text(respuesta)
|
| 29 |
except Exception as e:
|
| 30 |
+
error_msg = f"Error al conectar con la IA: {e}"
|
| 31 |
+
print(error_msg)
|
| 32 |
+
await update.message.reply_text(f"Hola Ricardo, recib铆 tu mensaje pero tengo este error: {e}")
|
| 33 |
|
| 34 |
if __name__ == '__main__':
|
| 35 |
if not TOKEN or not GROQ_KEY:
|
| 36 |
+
print("ERROR: Faltan las llaves en Settings (Secrets)")
|
| 37 |
else:
|
| 38 |
app = ApplicationBuilder().token(TOKEN).build()
|
| 39 |
app.add_handler(MessageHandler(filters.TEXT & (~filters.COMMAND), handle_message))
|
| 40 |
print("隆Bot despertando!")
|
| 41 |
app.run_polling()
|
| 42 |
+
|