removed premium requirement for dalle
This commit is contained in:
parent
0ae40e17e7
commit
a7255a613f
1 changed files with 22 additions and 29 deletions
|
|
@ -16,7 +16,6 @@ class ChatGPT(commands.Cog):
|
|||
self.API_KEY = os.getenv("openai.api_key")
|
||||
self.working_dir = "tmp/chatgpt/"
|
||||
self.data_dir = "data/chatgpt/"
|
||||
self.premium_role = 1200943915579228170
|
||||
self.folder_setup()
|
||||
self.remind_me_loop.start()
|
||||
self.http_session = self.create_aiohttp_session()
|
||||
|
|
@ -190,15 +189,12 @@ class ChatGPT(commands.Cog):
|
|||
brief="Get an answer"
|
||||
)
|
||||
async def question_gpt4(self, ctx):
|
||||
if ctx.author.get_role(self.premium_role):
|
||||
await ctx.send("One moment, let me think...")
|
||||
question = ctx.message.content.split(" ", maxsplit=1)[1]
|
||||
answer = await self.answer_question(question, "gpt-4-turbo-preview")
|
||||
chunks = [answer[i:i+1999] for i in range(0, len(answer), 1999)]
|
||||
for chunk in chunks:
|
||||
await ctx.send(chunk)
|
||||
else:
|
||||
await ctx.send("Sorry you must be a premium member to use this command. (!donate)")
|
||||
await ctx.send("One moment, let me think...")
|
||||
question = ctx.message.content.split(" ", maxsplit=1)[1]
|
||||
answer = await self.answer_question(question, "gpt-4-turbo-preview")
|
||||
chunks = [answer[i:i+1999] for i in range(0, len(answer), 1999)]
|
||||
for chunk in chunks:
|
||||
await ctx.send(chunk)
|
||||
|
||||
async def dalle_api_call(self, prompt: str, model: str="dall-e-2", quality: str="standard", size: str="1024x1024") -> tuple:
|
||||
data = {
|
||||
|
|
@ -228,25 +224,22 @@ class ChatGPT(commands.Cog):
|
|||
|
||||
|
||||
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]
|
||||
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)
|
||||
if resp_status != 200:
|
||||
await ctx.send(f"Error generating image: {resp_status}: {resp}")
|
||||
return
|
||||
my_filename = str(time.time_ns()) + ".png"
|
||||
image_filepath = f"{self.data_dir}dalle/{my_filename}"
|
||||
await self.download_image(resp, image_filepath)
|
||||
with open(image_filepath, "rb") as fh:
|
||||
f = discord.File(fh, filename=image_filepath)
|
||||
prompt = prompt.replace('\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:
|
||||
log_filepath.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)")
|
||||
prompt = ctx.message.content.split(" ", maxsplit=1)[1]
|
||||
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)
|
||||
if resp_status != 200:
|
||||
await ctx.send(f"Error generating image: {resp_status}: {resp}")
|
||||
return
|
||||
my_filename = str(time.time_ns()) + ".png"
|
||||
image_filepath = f"{self.data_dir}dalle/{my_filename}"
|
||||
await self.download_image(resp, image_filepath)
|
||||
with open(image_filepath, "rb") as fh:
|
||||
f = discord.File(fh, filename=image_filepath)
|
||||
prompt = prompt.replace('\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:
|
||||
log_filepath.writelines(log_data)
|
||||
await ctx.send(f'Generated by: {ctx.author.name}\nPrompt: {prompt}', file=f)
|
||||
|
||||
|
||||
@commands.command(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue