dsfs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pavel_Durov 2024-05-10 20:49:20 +03:00
parent 4c520b39fe
commit 1533c5eb91

View File

@ -1,4 +1,4 @@
import openai from openai import AsyncOpenAI
from aiogram import types from aiogram import types
from create_bot import dp, bot from create_bot import dp, bot
import logging import logging
@ -6,69 +6,59 @@ from global_conf import CONFIG
admins = CONFIG['telegram_admins_ids'] admins = CONFIG['telegram_admins_ids']
openai.api_key = "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"
ban_comands = ['/dick','/topdick'] ban_comands = ['/dick','/topdick']
# Image_promt =['тупица сгенерируй','тупица сгенерируй картинку',\ # Image_promt =['тупица сгенерируй','тупица сгенерируй картинку',\
# 'тупица отправь картинку', 'тупица отправь картинку'] # 'тупица отправь картинку', 'тупица отправь картинку']
client = AsyncOpenAI(api_key="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")
# @dp.message_handler(commands=['image'])
@dp.message_handler(commands=['image']) # async def send_image(message: types.Message):
async def send_image(message: types.Message): # if message.from_user.id in admins and message.chat.type == 'private':
if message.from_user.id in admins and message.chat.type == 'private': # try:
try: # description = message.text.replace('/image', '').strip()
description = message.text.replace('/image', '').strip()
if not description: # if not description:
await message.reply('Ты даун, описание запроса напиши после пробела') # await message.reply('Ты даун, описание запроса напиши после пробела')
return # return
except Exception as e: # except Exception as e:
logging.error(f'Error in send_image: {e}') # logging.error(f'Error in send_image: {e}')
try: # try:
response = openai.Image.create( # response = openai.Image.create(
prompt=message.text, # prompt=message.text,
n=1, # n=1,
size="1024x1024", # size="1024x1024",
response_format="url", # response_format="url",
) # )
image_url = response['data'][0]['url'] # image_url = response['data'][0]['url']
await message.answer('Генерирую изображение...') # await message.answer('Генерирую изображение...')
await message.reply_photo(image_url) # await message.reply_photo(image_url)
except Exception as e: # except Exception as e:
await message.reply('у меня не получилось') # await message.reply('у меня не получилось')
async def gpt_text(req):
completion = await client.chat.completions.create(
messages=[
{
"role": "user",
"content": req,
}
],
model="gpt-4",
)
return completion
@dp.message_handler() @dp.message_handler()
async def send(message: types.Message): async def send(message: types.Message):
if message.from_user.id in admins and message.chat.type == 'private': if message.from_user.id in admins and message.chat.type == 'private':
response = await gpt_text(message.text)
await message.answer(response.choices[0].message.content)
## TODO уточнить остатки токенов и денег
response = openai.ChatCompletion.create(
model="gpt-4",
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'])
elif message.reply_to_message.from_user.is_bot:
response = openai.Completion.create(
model="gpt-4-turbo",
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'])