Spaces:
Configuration error
Configuration error
| import os | |
| import asyncio | |
| from groq import Groq | |
| from telegram import Update | |
| from telegram.ext import Application, MessageHandler, filters, ContextTypes | |
| # CONFIGURATION | |
| GROQ_KEY = "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" | |
| TELEGRAM_TOKEN = "8239686025:AAEp_kfqMd_CMB0SN0SAHPGYyJ5-pXYVuZQ" | |
| client = Groq(api_key=GROQ_KEY) | |
| async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| try: | |
| # إرسال المهمة لنموذج Llama | |
| completion = client.chat.completions.create( | |
| model="llama-3.3-70b-versatile", | |
| messages=[{"role": "user", "content": update.message.text}] | |
| ) | |
| await update.message.reply_text(completion.choices[0].message.content) | |
| except Exception as e: | |
| print(f"Error: {e}") | |
| async def main(): | |
| # بناء وتشغيل البوت | |
| application = Application.builder().token(TELEGRAM_TOKEN).build() | |
| application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message)) | |
| async with application: | |
| await application.initialize() | |
| await application.start_polling() | |
| # Keep running 24/7 | |
| await asyncio.Event().wait() | |
| if __name__ == '__main__': | |
| try: | |
| asyncio.run(main()) | |
| except KeyboardInterrupt: | |
| pass | |