attempting to use endpoint
This commit is contained in:
parent
ab98ace3d7
commit
995a0090f9
@ -137,18 +137,23 @@ class ReginaldCog(commands.Cog):
|
|||||||
await ctx.author.send(f"I apologize, but I am unable to generate an image at this time. Error message: {str(e)}")
|
await ctx.author.send(f"I apologize, but I am unable to generate an image at this time. Error message: {str(e)}")
|
||||||
|
|
||||||
async def generate_image(self, api_key, prompt):
|
async def generate_image(self, api_key, prompt):
|
||||||
openai.api_key = api_key
|
url = "https://api.openai.com/v1/images/generations"
|
||||||
model = "image-alpha-001" # Replace this with the appropriate DALL-E model name
|
headers = {
|
||||||
response = openai.Image.create(
|
"Content-Type": "application/json",
|
||||||
model=model,
|
"Authorization": f"Bearer {api_key}",
|
||||||
prompt=prompt,
|
}
|
||||||
n=1,
|
data = {
|
||||||
size="512x512",
|
"prompt": prompt,
|
||||||
response_format="url"
|
"n": 1,
|
||||||
)
|
"size": "1024x1024",
|
||||||
|
}
|
||||||
|
|
||||||
if response and response.choices and response.choices[0].url:
|
async with aiohttp.ClientSession() as session:
|
||||||
return response.choices[0].url
|
async with session.post(url, headers=headers, data=json.dumps(data)) as resp:
|
||||||
|
response = await resp.json()
|
||||||
|
|
||||||
|
if response and "data" in response and len(response["data"]) > 0:
|
||||||
|
return response["data"][0]["url"]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@reginald.error
|
@reginald.error
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user