Modir19 commited on
Commit
32943fb
·
verified ·
1 Parent(s): 2018985

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import asyncio
3
+ from groq import Groq
4
+ from telegram import Update
5
+ from telegram.ext import Application, MessageHandler, filters, ContextTypes
6
+
7
+ # CONFIGURATION
8
+ GROQ_KEY = "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"
9
+ TELEGRAM_TOKEN = "8239686025:AAEp_kfqMd_CMB0SN0SAHPGYyJ5-pXYVuZQ"
10
+
11
+ client = Groq(api_key=GROQ_KEY)
12
+
13
+ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
14
+ try:
15
+ # إرسال المهمة لنموذج Llama
16
+ completion = client.chat.completions.create(
17
+ model="llama-3.3-70b-versatile",
18
+ messages=[{"role": "user", "content": update.message.text}]
19
+ )
20
+ await update.message.reply_text(completion.choices[0].message.content)
21
+ except Exception as e:
22
+ print(f"Error: {e}")
23
+
24
+ async def main():
25
+ # بناء وتشغيل البوت
26
+ application = Application.builder().token(TELEGRAM_TOKEN).build()
27
+ application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message))
28
+
29
+ async with application:
30
+ await application.initialize()
31
+ await application.start_polling()
32
+ # Keep running 24/7
33
+ await asyncio.Event().wait()
34
+
35
+ if __name__ == '__main__':
36
+ try:
37
+ asyncio.run(main())
38
+ except KeyboardInterrupt:
39
+ pass