Update runs/python/telegram_gemini.py
Browse files- runs/python/telegram_gemini.py +34 -34
runs/python/telegram_gemini.py
CHANGED
@@ -1,34 +1,34 @@
|
|
1 |
-
import requests
|
2 |
-
from telegram 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 |
-
system_prompt = f"User: {prompt}\nAssistant:"
|
11 |
-
payload = {
|
12 |
-
"prompt": system_prompt,
|
13 |
-
"max_tokens": 64,
|
14 |
-
"temperature": 0.7,
|
15 |
-
"stop": ["</s>", "User:"]
|
16 |
-
}
|
17 |
-
response = requests.post(LLAMA_API_URL, json=payload)
|
18 |
-
if response.ok:
|
19 |
-
return response.json()["content"].strip()
|
20 |
-
else:
|
21 |
-
return "خطا در ارتباط با مدل زبان."
|
22 |
-
|
23 |
-
|
24 |
-
# هندل کردن پیامهایی که با / شروع میشن
|
25 |
-
async def handle_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
26 |
-
message = update.message
|
27 |
-
user_input = message.text.lstrip('/gemma') # حذف اسلش اول
|
28 |
-
reply = get_llama_response(user_input)
|
29 |
-
await message.reply_text(reply)
|
30 |
-
|
31 |
-
# راهاندازی ربات
|
32 |
-
app = ApplicationBuilder().token(BOT_TOKEN).build()
|
33 |
-
app.add_handler(MessageHandler(filters.COMMAND, handle_command))
|
34 |
-
app.run_polling()
|
|
|
1 |
+
import requests
|
2 |
+
from telegram 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 |
+
system_prompt = f"User: {prompt}\nAssistant:"
|
11 |
+
payload = {
|
12 |
+
"prompt": system_prompt,
|
13 |
+
"max_tokens": 64,
|
14 |
+
"temperature": 0.7,
|
15 |
+
"stop": ["</s>", "User:"]
|
16 |
+
}
|
17 |
+
response = requests.post(LLAMA_API_URL, json=payload)
|
18 |
+
if response.ok:
|
19 |
+
return response.json()["content"].strip()
|
20 |
+
else:
|
21 |
+
return "خطا در ارتباط با مدل زبان."
|
22 |
+
|
23 |
+
|
24 |
+
# هندل کردن پیامهایی که با / شروع میشن
|
25 |
+
async def handle_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
26 |
+
message = update.message
|
27 |
+
user_input = message.text.lstrip('/gemma') # حذف اسلش اول
|
28 |
+
reply = get_llama_response(user_input)
|
29 |
+
await message.reply_text(reply)
|
30 |
+
|
31 |
+
# راهاندازی ربات
|
32 |
+
app = ApplicationBuilder().token(BOT_TOKEN).build()
|
33 |
+
app.add_handler(MessageHandler(filters.COMMAND, handle_command))
|
34 |
+
app.run_polling()
|