added dalle support
This commit is contained in:
parent
9c460d56b2
commit
0e8c6d8132
1 changed files with 51 additions and 0 deletions
|
|
@ -98,6 +98,30 @@ class ChatGPT(commands.Cog):
|
||||||
self.bot.logger.exception("Error occurred in answer_question")
|
self.bot.logger.exception("Error occurred in answer_question")
|
||||||
return "Error occurred in answer_question"
|
return "Error occurred in answer_question"
|
||||||
|
|
||||||
|
async def get_dalle(self, prompt, model="dall-e-2"):
|
||||||
|
headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': f'Bearer {os.getenv("openai.api_key")}',
|
||||||
|
}
|
||||||
|
data = {
|
||||||
|
"model": model,
|
||||||
|
"prompt": prompt,
|
||||||
|
"size": "1024x1024",
|
||||||
|
"quality": "standard",
|
||||||
|
"n":1,
|
||||||
|
}
|
||||||
|
url = "https://api.openai.com/v1/images/generations"
|
||||||
|
|
||||||
|
try:
|
||||||
|
async with self.bot.http_session.post(url, headers=headers, json=data) as resp:
|
||||||
|
response_data = await resp.json()
|
||||||
|
response = response_data[0]['url']
|
||||||
|
return response
|
||||||
|
|
||||||
|
except Exception as error:
|
||||||
|
self.bot.logger.exception("Error occurred in dalle")
|
||||||
|
return "Error occurred in dalle"
|
||||||
|
|
||||||
@commands.command(
|
@commands.command(
|
||||||
description="Personality",
|
description="Personality",
|
||||||
help="Set the personality of the bot. Usage: !personality (personality)",
|
help="Set the personality of the bot. Usage: !personality (personality)",
|
||||||
|
|
@ -174,6 +198,33 @@ class ChatGPT(commands.Cog):
|
||||||
else:
|
else:
|
||||||
await ctx.send("Sorry you must be a premium member to use this command. (!donate)")
|
await ctx.send("Sorry you must be a premium member to use this command. (!donate)")
|
||||||
|
|
||||||
|
@commands.command(
|
||||||
|
description="Dalle 2",
|
||||||
|
help="Generate an image with Dalle 2 Usage: !dalle2 (prompt)",
|
||||||
|
brief="Generate Image",
|
||||||
|
aliases = ['dalle']
|
||||||
|
)
|
||||||
|
async def dalle2(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)
|
||||||
|
await ctx.send("Generated by: {ctx.author.name}\nPrompt: {prompt}\n{img_url}")
|
||||||
|
else:
|
||||||
|
await ctx.send("Sorry you must be a premium member to use this command. (!donate)")
|
||||||
|
|
||||||
|
@commands.command(
|
||||||
|
description="Dalle 3",
|
||||||
|
help="Generate an image with Dalle 3 Usage: !dalle3 (prompt)",
|
||||||
|
brief="Generate Image"
|
||||||
|
)
|
||||||
|
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")
|
||||||
|
await ctx.send("Generated by: {ctx.author.name}\nPrompt: {prompt}\n{img_url}")
|
||||||
|
else:
|
||||||
|
await ctx.send("Sorry you must be a premium member to use this command. (!donate)")
|
||||||
|
|
||||||
@commands.command(
|
@commands.command(
|
||||||
description="Image GPT4",
|
description="Image GPT4",
|
||||||
help="Ask GPT4 a question about an image. Usage: !question_gpt4 (link) (question)",
|
help="Ask GPT4 a question about an image. Usage: !question_gpt4 (link) (question)",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue