python_bot/handlers/davinci.py
Simple_Not ef4c806071
All checks were successful
continuous-integration/drone/push Build is passing
#8 надеюсь не сломается
2024-01-21 22:33:15 +10:00

80 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import openai
from aiogram import types
from create_bot import dp, bot
import logging
from global_conf import CONFIG
token = CONFIG['openai']['token']
openai.api_key = CONFIG['openai']['api_key']
ban_comands = ['/dick','/topdick']
# Image_promt =['тупица сгенерируй','тупица сгенерируй картинку',\
# 'тупица отправь картинку', 'тупица отправь картинку']
@dp.message_handler(commands=['image'])
async def send_image(message: types.Message):
try:
description = message.text.replace('/image', '').strip()
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",
)
image_url = response['data'][0]['url']
await message.answer('Генерирую изображение...')
await message.reply_photo(image_url)
except Exception as e:
await message.reply('у меня не получилось')
@dp.message_handler()
async def send(message: types.Message):
if message.text.lower().startswith('тупица'):
## TODO уточнить остатки токенов и денег
response = openai.Completion.create(
model="text-davinci-003",
prompt=message.text[7:],
temperature=0.7,
max_tokens=1000,
top_p=1.0,
frequency_penalty=0.0,
presence_penalty=0.6,
stop=["сброс"]
)
await message.reply(response['choices'][0]['text'])
elif message.reply_to_message.from_user.is_bot:
response = openai.Completion.create(
model="text-davinci-003",
prompt=message.text,
temperature=0.7,
max_tokens=1000,
top_p=1.0,
frequency_penalty=0.0,
presence_penalty=0.6,
stop=["сброс"]
)
await message.reply(response['choices'][0]['text'])