diff --git a/matrixai/__init__.py b/matrixai/__init__.py index 0c1af93..04ae3bc 100644 --- a/matrixai/__init__.py +++ b/matrixai/__init__.py @@ -751,8 +751,40 @@ def run(): await imagine.close() return img_file - filename = await generate_image(prompt, style, ratio, negative, upscale=False) + async def generate_dalle_image(prompt, size): + base_urls = ['https://a.z-pt.com'] + endpoint = '/api/openai/v1/images/generations' + headers = { + 'Content-Type': 'application/json', + } + data = { + 'prompt': prompt, + 'n': 1, + 'size': size + } + async with aiohttp.ClientSession() as session: + for base_url in base_urls: + url = base_url + endpoint + async with session.post(url, headers=headers, json=data) as response: + if response.status != 200: + continue + + response_data = await response.json() + if 'error' in response_data: + return None + + image_url = response_data['data'][0]['url'] + async with session.get(image_url) as image_response: + image_content = await image_response.read() + img_file = io.BytesIO(image_content) + return img_file + + return None + + #filename = await generate_image(prompt, style, ratio, negative, upscale=False) + + filename = await generate_dalle_image(prompt, 512) await bot.api.send_image_message( room_id=room.room_id, image_filepath=filename )