From 0ccd421f8ba7b2f830df5d99bd06b3d226b00e09 Mon Sep 17 00:00:00 2001 From: phixxy Date: Sat, 27 Jan 2024 22:13:07 -0800 Subject: [PATCH] added dalle3hd --- extensions/chatgpt.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/extensions/chatgpt.py b/extensions/chatgpt.py index 686f48f..8f3da86 100644 --- a/extensions/chatgpt.py +++ b/extensions/chatgpt.py @@ -103,7 +103,7 @@ class ChatGPT(commands.Cog): self.bot.logger.exception("Error occurred in answer_question") return "Error occurred in answer_question" - async def get_dalle(self, prompt, model="dall-e-2"): + async def get_dalle(self, prompt, model="dall-e-2", quality="standard", size="1024x1024"): headers = { 'Content-Type': 'application/json', 'Authorization': f'Bearer {os.getenv("openai.api_key")}', @@ -111,8 +111,8 @@ class ChatGPT(commands.Cog): data = { "model": model, "prompt": prompt, - "size": "1024x1024", - "quality": "standard", + "size": size, + "quality": quality, "n":1, } url = "https://api.openai.com/v1/images/generations" @@ -241,7 +241,28 @@ class ChatGPT(commands.Cog): async def dalle3(self, ctx): if ctx.author.get_role(self.premium_role): prompt = ctx.message.content.split(" ", maxsplit=1)[1] - img_url = await self.get_dalle(prompt, "dall-e-3") + img_url = await self.get_dalle(prompt, model="dall-e-3") + my_filename = str(time.time_ns()) + ".png" + filepath = f"{self.data_dir}dalle/{my_filename}" + await self.download_image(img_url, filepath) + with open(filepath, "rb") as fh: + f = discord.File(fh, filename=filepath) + 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_file: + log_file.writelines(log_data) + 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( + description="Dalle 3 HD", + help="Generate an HD image with Dalle 3 Usage: !dalle3 (prompt)", + brief="Generate HD Image", + ) + async def dalle3hd(self, ctx): + if ctx.author.get_role(self.premium_role): + prompt = ctx.message.content.split(" ", maxsplit=1)[1] + img_url = await self.get_dalle(prompt, model="dall-e-3", quality="hd", size="1792x1024") my_filename = str(time.time_ns()) + ".png" filepath = f"{self.data_dir}dalle/{my_filename}" await self.download_image(img_url, filepath)