omit empty values with Image API clients #615
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
HI, I came across this project and I tried to use Image APIs. Then, I found that some optional parameters must be specify to call APIs, or it returns 400 error.
For example, according to the API specification of Create image variation API, the parameters
n
,response_format
, andsize
are optional, and if those parameters aren't specified, the API applies default values.However, in
go-openai
client, if those parameter aren't specified explicitly, it sends zero values and gets 400 response.if I make a request like this:
then, I got a response like this:
because client actually send a request like this:
Although the request structs have fields with json struct tag and seemingly intend to
omitempty
, actually thisomitempty
doesn't work because those API acceptmultipart/form-data
so request aren't marshaled to json.Describe the change
Then, I made image API client work even if optional parameters aren't set in request structs.
Provide OpenAI documentation link
Describe your solution
I just wrote
if
to check zero values. This change will work same asomitempty
. As discussed #9 , it cannot express the difference between zero value and intended zero or empty string though. Another alternative might be using a null structs likeNullInt
orNullString
but it would make breaking changes though.If my changes would be acceptable, I'd make changes in other image API clients that request with
multipart/form-data
format and write tests. If it was already argued or you don't need this changes, please close it. Thanks😃