Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telebot
- import openai
- bot = telebot.TeleBot("***********************************************************")
- openai.api_key = "sk-*******************************************"
- @bot.message_handler(content_types=['text'])
- def lalala(message):
- print(message.chat.title, message.chat.username)
- if message.chat.id == -1001411081071:
- #print(message.text)
- if "@mbajan_bot" in message.text:
- message.text = (message.text).replace("@mbajan_bot ", "")
- #print(message.text)
- response = openai.Completion.create(model="text-davinci-003", prompt=message.text, max_tokens=1000)
- full_response = response['choices'][0]['text'] # Use the text property of the first element of the choices list to access the full response
- lines = full_response.splitlines() # Split the response into individual lines
- for line in lines: # Iterate over the lines
- try:
- #print(line)
- bot.send_message(message.chat.id, line) # Send each line back to the user as a separate message
- except Exception as e:
- print(e)
- else:
- bot.send_message(message.chat.id, "Вибачте, доступний тільки в группі https://t.me/python_for_dummies")
- bot.polling(none_stop=True, interval=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement