File size: 1,301 Bytes
32943fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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