ysn-rfd commited on
Commit
f151779
·
verified ·
1 Parent(s): 07b3f15

Update runs/python/gemini_telegram.py

Browse files
Files changed (1) hide show
  1. runs/python/gemini_telegram.py +36 -36
runs/python/gemini_telegram.py CHANGED
@@ -1,36 +1,36 @@
1
- import requests
2
- from telegram_gemini import Update
3
- from telegram.ext import ApplicationBuilder, MessageHandler, ContextTypes, filters
4
-
5
- BOT_TOKEN = "7490823724:AAEcskSIKg9t63nBME3Igkxw_QE4dl2Ql_U"
6
- LLAMA_API_URL = "http://127.0.0.1:8080/completion"
7
-
8
- # تابع گرفتن پاسخ از سرور llama.cpp
9
- def get_llama_response(prompt):
10
- payload = {
11
- "prompt": prompt,
12
- "max_tokens": 256,
13
- "temperature": 0.7,
14
- "stop": ["</s>", "User:"]
15
- }
16
- response = requests.post(LLAMA_API_URL, json=payload)
17
- if response.ok:
18
- return response.json()["content"].strip()
19
- else:
20
- return "خطا در ارتباط با مدل زبان."
21
-
22
- # تابع هندل پیام تلگرام
23
- async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
24
- user_input = update.message.text
25
- reply = get_llama_response(user_input)
26
- await update.message.reply_text(reply)
27
-
28
- # راه‌اندازی ربات
29
- app = ApplicationBuilder().token(BOT_TOKEN).build()
30
- app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message))
31
- app.run_polling()
32
-
33
-
34
-
35
-
36
-
 
1
+ import requests
2
+ from telegram_gemini import Update
3
+ from telegram.ext import ApplicationBuilder, MessageHandler, ContextTypes, filters
4
+
5
+ BOT_TOKEN = ""
6
+ LLAMA_API_URL = "http://127.0.0.1:8080/completion"
7
+
8
+ # تابع گرفتن پاسخ از سرور llama.cpp
9
+ def get_llama_response(prompt):
10
+ payload = {
11
+ "prompt": prompt,
12
+ "max_tokens": 256,
13
+ "temperature": 0.7,
14
+ "stop": ["</s>", "User:"]
15
+ }
16
+ response = requests.post(LLAMA_API_URL, json=payload)
17
+ if response.ok:
18
+ return response.json()["content"].strip()
19
+ else:
20
+ return "خطا در ارتباط با مدل زبان."
21
+
22
+ # تابع هندل پیام تلگرام
23
+ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
24
+ user_input = update.message.text
25
+ reply = get_llama_response(user_input)
26
+ await update.message.reply_text(reply)
27
+
28
+ # راه‌اندازی ربات
29
+ app = ApplicationBuilder().token(BOT_TOKEN).build()
30
+ app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message))
31
+ app.run_polling()
32
+
33
+
34
+
35
+
36
+