removed premium requirement for dalle

This commit is contained in:
phixxy 2024-03-09 21:26:09 -08:00
parent 0ae40e17e7
commit a7255a613f

View file

@ -16,7 +16,6 @@ class ChatGPT(commands.Cog):
self.API_KEY = os.getenv("openai.api_key") self.API_KEY = os.getenv("openai.api_key")
self.working_dir = "tmp/chatgpt/" self.working_dir = "tmp/chatgpt/"
self.data_dir = "data/chatgpt/" self.data_dir = "data/chatgpt/"
self.premium_role = 1200943915579228170
self.folder_setup() self.folder_setup()
self.remind_me_loop.start() self.remind_me_loop.start()
self.http_session = self.create_aiohttp_session() self.http_session = self.create_aiohttp_session()
@ -190,15 +189,12 @@ class ChatGPT(commands.Cog):
brief="Get an answer" brief="Get an answer"
) )
async def question_gpt4(self, ctx): async def question_gpt4(self, ctx):
if ctx.author.get_role(self.premium_role): await ctx.send("One moment, let me think...")
await ctx.send("One moment, let me think...") question = ctx.message.content.split(" ", maxsplit=1)[1]
question = ctx.message.content.split(" ", maxsplit=1)[1] answer = await self.answer_question(question, "gpt-4-turbo-preview")
answer = await self.answer_question(question, "gpt-4-turbo-preview") chunks = [answer[i:i+1999] for i in range(0, len(answer), 1999)]
chunks = [answer[i:i+1999] for i in range(0, len(answer), 1999)] for chunk in chunks:
for chunk in chunks: await ctx.send(chunk)
await ctx.send(chunk)
else:
await ctx.send("Sorry you must be a premium member to use this command. (!donate)")
async def dalle_api_call(self, prompt: str, model: str="dall-e-2", quality: str="standard", size: str="1024x1024") -> tuple: async def dalle_api_call(self, prompt: str, model: str="dall-e-2", quality: str="standard", size: str="1024x1024") -> tuple:
data = { data = {
@ -228,25 +224,22 @@ class ChatGPT(commands.Cog):
async def generate_dalle_image(self, ctx, model, quality="standard", size="1024x1024") -> None: async def generate_dalle_image(self, ctx, model, quality="standard", size="1024x1024") -> None:
if ctx.author.get_role(self.premium_role): prompt = ctx.message.content.split(" ", maxsplit=1)[1]
prompt = ctx.message.content.split(" ", maxsplit=1)[1] await ctx.send(f"Please be patient this may take some time! Generating: {prompt}.")
await ctx.send(f"Please be patient this may take some time! Generating: {prompt}.") resp_status, resp = await self.dalle_api_call(prompt, model=model, quality=quality, size=size)
resp_status, resp = await self.dalle_api_call(prompt, model=model, quality=quality, size=size) if resp_status != 200:
if resp_status != 200: await ctx.send(f"Error generating image: {resp_status}: {resp}")
await ctx.send(f"Error generating image: {resp_status}: {resp}") return
return my_filename = str(time.time_ns()) + ".png"
my_filename = str(time.time_ns()) + ".png" image_filepath = f"{self.data_dir}dalle/{my_filename}"
image_filepath = f"{self.data_dir}dalle/{my_filename}" await self.download_image(resp, image_filepath)
await self.download_image(resp, image_filepath) with open(image_filepath, "rb") as fh:
with open(image_filepath, "rb") as fh: f = discord.File(fh, filename=image_filepath)
f = discord.File(fh, filename=image_filepath) prompt = prompt.replace('\n',' ')
prompt = prompt.replace('\n',' ') log_data = f'Author: {ctx.author.name}, Prompt: {prompt}, Filename: {my_filename}\n'
log_data = f'Author: {ctx.author.name}, Prompt: {prompt}, Filename: {my_filename}\n' with open(f"{self.data_dir}logs/dalle3.log", 'a') as log_filepath:
with open(f"{self.data_dir}logs/dalle3.log", 'a') as log_filepath: log_filepath.writelines(log_data)
log_filepath.writelines(log_data) await ctx.send(f'Generated by: {ctx.author.name}\nPrompt: {prompt}', file=f)
await ctx.send(f'Generated by: {ctx.author.name}\nPrompt: {prompt}', file=f)
else:
await ctx.send("Sorry you must be a premium member to use this command. (!donate)")
@commands.command( @commands.command(