-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
66 lines (54 loc) · 2.13 KB
/
Main.py
File metadata and controls
66 lines (54 loc) · 2.13 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters, ContextTypes
import openai
import os
# 🔐 KEYS
BOT_TOKEN = "8359897581:AAEUsBf_zOY_d7PxgGM-BgmnaxSFx_C-fvg"
OPENAI_KEY = "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"
openai.api_key = OPENAI_KEY
# /start
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(
"👋 Hello! I am *OlaGPT* 🤖\nAn AI assistant.\nType anything!",
parse_mode="Markdown"
)
# /help
async def help_cmd(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(
"/start - Start the bot\n"
"/help - Show help\n"
"/about - About OlaGPT\n\n"
"Just type a message to chat with AI 🤖"
)
# /about
async def about(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(
"🤖 *OlaGPT*\n"
"Powered by ChatGPT AI\n"
"Created by Ola\n"
"Smart • Fast • Friendly",
parse_mode="Markdown"
)
# AI Reply
async def ai_reply(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_text = update.message.text
try:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant called OlaGPT."},
{"role": "user", "content": user_text}
]
)
reply = response["choices"][0]["message"]["content"]
await update.message.reply_text(reply)
except Exception as e:
await update.message.reply_text("⚠️ Error. Try again later.")
# BOT SETUP
app = ApplicationBuilder().token(BOT_TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(CommandHandler("help", help_cmd))
app.add_handler(CommandHandler("about", about))
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, ai_reply))
print("🤖 OlaGPT AI is running...")
app.run_polling()