#image edit endpoint... w PHP CURL

113 messages · Page 1 of 1 (latest)

burnt prism
#

{ "error": { "code": null, "message": "'image' is a required property", "param": null, "type": "invalid_request_error" } }

I'm obviously not sending the image right., I have a multipart header now, and I've tried several things to send the image. Docs say they want a string...

I'm sending this... "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAMAAABrrFhUAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyNpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUhdatadatadata"

I've tried the @filename, but that's not working either. Even tried curl_file_create...

any ideas?

#

$payload = array( "prompt"=> $prompt, "n"=> $numimages, "image"=> "$base64aa", "mask"=> "$base64bb", "size"=> $imgsize, "response_format"=> $resp_form, "user"=> "$usrid");

#

$patha = './thefile.png';

$typea = pathinfo($patha, PATHINFO_EXTENSION);
$dataa = file_get_contents($patha,"rb");
$base64aa = 'data:image/' . $typea . ';base64,' . base64_encode($dataa);

teal crow
#

Could be that you're not sending the right formatted data with the image?

burnt prism
#

yea i think that's what it is, but not sure why...

teal crow
#

Mainly because probably OpenAI's server only reads a certain type of image data.

#

I'd say look into PHP functions that convert binary images into that formatting.

burnt prism
#

it could be the php curl wrapper

#

yea i'm trying a few different ways

#

i'm sending as base64 string, but it's not accepting it for some reason

#

thanks, tho!

#

{ "error": { "code": null, "message": "'image' is a required property", "param": null, "type": "invalid_request_error" } }

#

pretty sure that means it's not getting the image right heh

teal crow
#

I had the same issue too, maybe also look into how the data packet is formatted with the PHP cURL wrapper compared to a regular cURL request.

#

Mainly using --trace

burnt prism
#

alas that might be above my paygrade, but i'll keep digging

teal crow
#

Actually it's a lot more easier than you think.

#

The packet is in pretty fairly transparent regular text, so looking into the trace result could uncover something you're missing.

#

It helped me out.

burnt prism
#

i'm not running from Command line, tho?

#

i've done print_r on the payload and it looks ok

#

i changed it to multipart/form too

#

for the header

#

curl_file_create should be working

#

let me dig into his wrapper

teal crow
#

Maybe this'll help too:

#
private func dataFormField(named name: String, formData: FormData) -> Data {
        let fieldData = NSMutableData()

        fieldData.append("--\(boundary)\r\n")
        fieldData.append("Content-Disposition: form-data; name=\"\(name)\"; filename=\"\(formData.fileName)\"\r\n")
        fieldData.append("Content-Type: \(formData.mimeType)\r\n")
        fieldData.append("\r\n")
        fieldData.append(formData.data)
        fieldData.append("\r\n")

        return fieldData as Data
    }
#

It's the swift function I got working for my own project that formats the data header for a form request.

#

Maybe this'll help out in some way?

burnt prism
#

i'm trying to replicate that wrapper code but still getting same error

#

{ "error": { "code": null, "message": "'image' is a required property", "param": null, "type": "invalid_request_error" } }

#

so it must not be getting the image right

lethal condor
#

I don't see your version of the wrapper?

#

oh never mind, that is Swift code, I thought it was PHP

#

So you are using curl from PHP?

burnt prism
#

yea my code was a bit diff than his for curl

#

Array ( [image] => data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAQAAAAB0CZXLAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAd2KE6QAAAAHdElNRQfmCxQRDhwzBBtgAAAAM0lEQVRo3u3KoQEAAAwCIP9/Wk9YXYBMeoggCIIgCIIgCIIgCIIgCIIdatadatadatadata [mask] => data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAQAAAD2e2DtAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAdatadata [prompt] => MYPROMPT. [n] => 1 [size] => 256x256 [response_format] => b64_json [user] => 2 )

#

this is the payload i'm sending. maybe the string for the blob is wrong?

burnt prism
#

The open-AI php wrapper seems to send teh image, but it errors out without giving me anything back... hrm...

#

Okay got the PHP wrapper working... must be something in my code altho i replicated his curl method exactly... i'll keep tinkering... getting closer

bronze silo
#

The @ works in regular curl, what’s the error?

burnt prism
#

{ "error": { "code": null, "message": "'image' is a required property", "param": null, "type": "invalid_request_error" } }

#

The wrapper code seems to be working. Not sure how my curl code was different

#

I've got it working with the wrapper now in my code

#

i think it's the PHP CURL that doesn't like the @filename method?

#

The wrapper is using curl_file_create too but when I tried that i couldn't get anything back

#

the wrapper isn't huge, but i'm curious now heh

burnt prism
#

i wonder if php curl has something to do with me still getting so many 502 errors randomly?

lethal condor
burnt prism
#

i get them about 1 out of 10 or 20 requests

#

i'm starting to think it's php curl...

#

or maybe it's my php timing out occasionally?

lethal condor
burnt prism
#

personal? stable. server is dedicated and doesn't have probs with other stuff

#

i think openai is dropping connection and then php shuts it down?

#

could be bad programming too heh

lethal condor
burnt prism
#

the edit endpoint is working now, but still get occasional 502's with all requests

#

it's usually sooner than the timeout, tho... like usually always 4 or 5 seconds

#

maybe it is timing out but only occasionally

#

php timing out that is

#

i've got the timeout for the ajax connection to 25 seconds too

lethal condor
burnt prism
#

yea it works 9 out of 10

lethal condor
#

hmm

burnt prism
#

recv() failed (104: Connection reset by peer) while reading response header from upstream,

#

getting that in nginx error log

#

altho upstream is my .php.sock i think

#

so maybe it is my php timing out

lethal condor
#

Sorry, don't know. hopefully someone on the server side can take a look at your requests

burnt prism
#

no worries. thanks for trying.

#

and i had probs before on the requests because i'm using PHP cURL

#

was a password/authentication prob before

#

i might just switch out all my curl code and use the PHP wrapper... or set up a test with that to see if it errors out occasionally

lethal condor
#

ah well glad you got that sorted.

#

yeah, I was going to just suggest trying a different way to see if it still randomly occurs

burnt prism
#

i'll set some time aside for it this week amidst client work

#

thankfully (???) not getting a ton of traffic hah

lethal condor
#

oh it's live?

burnt prism
#

yea about a week now?

#

been live for 2 years now, but images live about a week

#

i just pop a notification if it fails now and ask them to try again

lethal condor
#

ah cool. looks fun. I was into Teenage Mutant Ninja Turtles and Hero's Unlimited when I was a kid. But now anything on the computer/console feels too much like work

burnt prism
#

yea the VTT (virtual tabletop) gamers are digging it... i've got a small group of authors/publishers too

lethal condor
#

neat

burnt prism
#

an API for the 40,000 generations in our library is on the sched for 2023

#

i have 2 options for people... they can generate for cheap (and give me all the rights to make it available to the community for non-commercial use) then a separate license if people want to buy the generations outright (more the authors and publishers)

#

most gamers are going for the cheaper price because they just want to use it in their game, so i've built up a sizable database of content

#

have used some of it to fine-tune... just not enough time to do everything - also self-funded

#

so i think some of the value i offer is not only the RPG tools but also the huge library of gaming content

#

netflix for dnd heh

lethal condor
#

Heck ya. Sounds like a nice little niche you carved out for yourself. I wish you continued success.

burnt prism
#

Thanks. I'm waiting for a competitor any day now. Heh.

#

You as well. Are you launching something?

lethal condor
#

Yeah using Dall•E in a comic building app

burnt prism
#

oh crap you told me that already. i'm so fried. sorry.

#

i love that idea too...

lethal condor
#

no worries!

burnt prism
#

anyway, i got edit endpoint working i just have to figure out this random 502 issue

#

tho i'll probably leave this up for any other php weirdos out there haha

lethal condor
#

thanks. I've been at it for a while. My ComicBook! app was named Best iPad Photo App of 2012 by Apple. but this is a brand new title I started from scratch - look ma no legacy code!

#

Speaking of which, better get my nose back in some code. Cheers.

burnt prism
#

Oh, nice. Cheers for now.

#

Break a keyboard.

wheat hedge
#

Hi @burnt prism is everything okay? I'm the repo owner, I can help

burnt prism
#

Yeah, got it working. Thanks.