#How to correctly make an AIOHTTP request to the image variations endpoint

25 messages · Page 1 of 1 (latest)

inner escarp
#

Hey! I've been trying to figure out how to correctly use AIOHTTP to make a request to the image variations endpoint, and no matter what I try, I'm unable to send the image data correctly, what format is it supposed to be in? Base64? Is it supposed to be sent as multipart form data (e.g the "image" field" is a separate field in the multipart form?)?

If anyone has sample code for a request made using AIOHTTP to https://api.openai.com/v1/images/variations that'd be awesome.

wooden compass
#

Interesting that the API reference does not specify how to send the image.

wooden compass
#

The official Python implementation seems to send it as a raw octet stream

inner escarp
inner escarp
#

I’ll try it out and update here soon

wooden compass
inner escarp
#

It’s fully blocking on the GIL when a request is being sent

wooden compass
#

Hope you managed to get it to work

inner escarp
#

Still working on it, I see that they're using application/octet-stream and when I was trying earlier I was using image/png for the file, which probably wasn't right

#

but it still doesn't work for me if I simply do a POST request with a file named "image" (octet stream)

#

Maybe there's differences in how AIOHTTP handles it or soemthing

wooden compass
#

I think it’s unlikely the issue lies in the HTTP library. Anyhow, have you considered emailing OpenAI about this?

inner escarp
#

I absolutely can't figure it out

#

Anyone have any thoughts????

#
TypeError: Can not serialize value type: <class 'int'>
 headers: {}
 value: 1
#

Something to do with the image, i tried changing it's type, tried sending as post, no clue how to proceed anymore. Why is this so hard???

#
import aiohttp
import asyncio

async def main():
    async with aiohttp.ClientSession() as session:
        data = aiohttp.FormData()
        data.add_field("n", 1)
        data.add_field("size", "512x512")
        with open("test.png", "rb") as f:
            data.add_field("image", f, filename="test.png", content_type="image/png")

        async with session.post(
            "https://api.openai.com/v1/images/variations",
            headers={
                "Authorization": "Bearer KEY",
            },
            data=data
        ) as resp:
            print(await resp.text())

if __name__ == "__main__":
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
    asyncio.run(main())
cursive arch
#

I am having similar problems with the edits api. No matter how I try to send the request, I just get back: { "error": { "code": null, "message": "'image' is a required property", "param": null, "type": "invalid_request_error" } }

#

however, my request would seem to have the image field: `HTTP request body:
--588721DBCCB07C4627D9A6537ACF16BD
Content-Disposition: form-data; name="image"
Content-Type: image/png

‰PNG


IHDR    ôxÔú pHYs `

inner escarp
# cursive arch I am having similar problems with the edits api. No matter how I try to send the...

Hey! I resolved this issue, you can check out my repo for how to make the request to variations and edits 😄 https://github.com/Kav-K/GPT3Discord

GitHub

A robust, but simple GPT3 interface with Discord. Chat just like ChatGPT right inside Discord! Generate beautiful AI art using DALL-E 2! - GitHub - Kav-K/GPT3Discord: A robust, but simple GPT3 inte...

#

in openai_model.py