-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
34 lines (27 loc) · 1.01 KB
/
bot.py
File metadata and controls
34 lines (27 loc) · 1.01 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
from dotenv import load_dotenv
from os import getenv
from telebot import TeleBot
from google import genai
from google.genai import types
load_dotenv()
bot = TeleBot(getenv('token'))
client = genai.Client()
@bot.message_handler(commands=['start'])
def welcome(message):
bot.reply_to(message, "Hello, I am AlaX. A general purpose virtual assistant. How can I help you?")
@bot.message_handler(func=lambda msg: True)
def reply(message):
try:
response = client.models.generate_content(
model="gemini-2.5-flash",
contents=message.text,
config=types.GenerateContentConfig(thinking_config=types.ThinkingConfig(thinking_budget=0))
)
if response.text:
bot.reply_to(message, response.text)
else:
bot.reply_to(message, "Sorry, I couldn't generate a response.")
except Exception as e:
print(f"Error: {e}")
bot.reply_to(message, "Sorry, there was an error processing your request.")
bot.infinity_polling()