-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbotGPT.py
38 lines (27 loc) · 831 Bytes
/
botGPT.py
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
import os
from dotenv import load_dotenv
import openai
from aiogram import Bot, Dispatcher, executor, types
from keep_alive import keep_alive
load_dotenv()
bot = Bot(token=os.getenv("tl_token"))
dp = Dispatcher(bot)
openai.api_key = os.getenv("oai_token")
keep_alive()
@dp.message_handler(commands=['start', 'help'])
async def welcome(message: types.Message):
await message.reply('Olá! Qual a sua pergunta?')
@dp.message_handler()
async def gpt(message: types.Message):
response = openai.Completion.create(
model="text-davinci-003",
prompt=message.text,
temperature=0.5,
max_tokens=1024,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.0
)
await message.reply(response.choices[0].text)
if __name__ == "__main__":
executor.start_polling(dp)