python_bot/handlers/davinci.py

71 lines
2.1 KiB
Python
Raw Normal View History

2024-05-11 03:49:20 +10:00
from openai import AsyncOpenAI
from aiogram import types
2023-02-06 21:54:41 +10:00
from create_bot import dp, bot
2023-07-21 06:10:49 +10:00
import logging
from global_conf import CONFIG
2024-05-11 03:37:34 +10:00
2024-05-11 02:46:37 +10:00
admins = CONFIG['telegram_admins_ids']
2023-07-17 15:18:56 +10:00
2024-05-11 03:49:20 +10:00
2023-07-18 07:39:15 +10:00
ban_comands = ['/dick','/topdick']
2023-07-17 15:21:28 +10:00
2023-07-21 06:10:49 +10:00
# Image_promt =['тупица сгенерируй','тупица сгенерируй картинку',\
# 'тупица отправь картинку', 'тупица отправь картинку']
2024-05-11 03:49:20 +10:00
client = AsyncOpenAI(api_key="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")
2023-07-21 06:10:49 +10:00
2024-05-11 03:49:20 +10:00
# @dp.message_handler(commands=['image'])
# async def send_image(message: types.Message):
# if message.from_user.id in admins and message.chat.type == 'private':
# try:
# description = message.text.replace('/image', '').strip()
2024-05-11 02:46:37 +10:00
2024-05-11 03:49:20 +10:00
# if not description:
# await message.reply('Ты даун, описание запроса напиши после пробела')
# return
# except Exception as e:
# logging.error(f'Error in send_image: {e}')
# try:
# response = openai.Image.create(
# prompt=message.text,
# n=1,
# size="1024x1024",
# response_format="url",
2024-05-11 02:46:37 +10:00
2024-05-11 03:49:20 +10:00
# )
# image_url = response['data'][0]['url']
# await message.answer('Генерирую изображение...')
# await message.reply_photo(image_url)
# except Exception as e:
# await message.reply('у меня не получилось')
async def gpt_text(req):
completion = await client.chat.completions.create(
messages=[
{
"role": "user",
"content": req,
}
],
model="gpt-4",
)
return completion
2023-07-21 06:10:49 +10:00
2023-02-06 21:54:41 +10:00
@dp.message_handler()
2023-02-06 22:45:18 +10:00
async def send(message: types.Message):
2024-05-11 02:46:37 +10:00
if message.from_user.id in admins and message.chat.type == 'private':
2024-05-11 03:49:20 +10:00
response = await gpt_text(message.text)
await message.answer(response.choices[0].message.content)
2023-02-06 21:54:41 +10:00
2023-07-21 06:10:49 +10:00
2023-07-18 06:39:33 +10:00
2023-02-06 21:54:41 +10:00