fix(images): 规范 OpenAI 图像尺寸参数
This commit is contained in:
@@ -65,6 +65,7 @@ func (c OpenAIClient) Run(ctx context.Context, request Request) (Response, error
|
||||
}
|
||||
}
|
||||
body["model"] = upstreamModelName(request.Candidate)
|
||||
normalizeOpenAIImageRequestBody(endpointKind, body)
|
||||
stream := openAIEndpointSupportsStream(endpointKind) && (request.Stream || boolValue(body, "stream"))
|
||||
ensureOpenAIStreamUsage(body, endpointKind, stream)
|
||||
raw, contentType, err := openAIRequestPayload(endpointKind, body, request.Candidate)
|
||||
@@ -171,6 +172,24 @@ func (c OpenAIClient) Run(ctx context.Context, request Request) (Response, error
|
||||
}, nil
|
||||
}
|
||||
|
||||
func normalizeOpenAIImageRequestBody(endpointKind string, body map[string]any) {
|
||||
if endpointKind != "images.generations" && endpointKind != "images.edits" {
|
||||
return
|
||||
}
|
||||
// OpenAI image endpoints express output geometry through size. The Gateway
|
||||
// keeps the generic fields for capability validation and billing, but they
|
||||
// are not valid OpenAI wire parameters.
|
||||
for _, key := range []string{
|
||||
"aspect_ratio",
|
||||
"aspectRatio",
|
||||
"resolution",
|
||||
"width",
|
||||
"height",
|
||||
} {
|
||||
delete(body, key)
|
||||
}
|
||||
}
|
||||
|
||||
func openAIRequestPayload(endpointKind string, body map[string]any, candidate store.RuntimeModelCandidate) ([]byte, string, error) {
|
||||
if endpointKind != "images.edits" {
|
||||
raw, err := json.Marshal(body)
|
||||
|
||||
Reference in New Issue
Block a user