match codex image request payload
This commit is contained in:
parent
135f721dfc
commit
05e4538883
2 changed files with 33 additions and 2 deletions
|
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
codexDefaultImageGenerationModel = "gpt-image-2"
|
codexDefaultImageGenerationModel = "gpt-image-2"
|
||||||
|
codexDefaultImageGenerationSize = "1024x1024"
|
||||||
maxImageGenerationResults = 4
|
maxImageGenerationResults = 4
|
||||||
maxImageGenerationSSEBytes = 64 * 1024 * 1024
|
maxImageGenerationSSEBytes = 64 * 1024 * 1024
|
||||||
maxImageGenerationEvents = 512
|
maxImageGenerationEvents = 512
|
||||||
|
|
@ -93,9 +94,14 @@ func (p *CodexProvider) requestOptions() ([]option.RequestOption, string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildCodexImageParams(req ImageGenerationRequest) responses.ResponseNewParams {
|
func buildCodexImageParams(req ImageGenerationRequest) responses.ResponseNewParams {
|
||||||
|
size := strings.TrimSpace(req.Size)
|
||||||
|
if size == "" {
|
||||||
|
size = codexDefaultImageGenerationSize
|
||||||
|
}
|
||||||
|
|
||||||
tool := responses.ToolUnionParam{OfImageGeneration: &responses.ToolImageGenerationParam{
|
tool := responses.ToolUnionParam{OfImageGeneration: &responses.ToolImageGenerationParam{
|
||||||
Model: req.Model,
|
Model: req.Model,
|
||||||
Size: req.Size,
|
Size: size,
|
||||||
}}
|
}}
|
||||||
if req.Quality != "" {
|
if req.Quality != "" {
|
||||||
tool.OfImageGeneration.Quality = req.Quality
|
tool.OfImageGeneration.Quality = req.Quality
|
||||||
|
|
@ -104,10 +110,17 @@ func buildCodexImageParams(req ImageGenerationRequest) responses.ResponseNewPara
|
||||||
tool.OfImageGeneration.OutputFormat = req.OutputFormat
|
tool.OfImageGeneration.OutputFormat = req.OutputFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content := responses.ResponseInputMessageContentListParam{
|
||||||
|
responses.ResponseInputContentParamOfInputText(req.Prompt),
|
||||||
|
}
|
||||||
|
input := responses.ResponseInputParam{
|
||||||
|
responses.ResponseInputItemParamOfMessage(content, responses.EasyInputMessageRoleUser),
|
||||||
|
}
|
||||||
|
|
||||||
return responses.ResponseNewParams{
|
return responses.ResponseNewParams{
|
||||||
Model: "gpt-5.4",
|
Model: "gpt-5.4",
|
||||||
Input: responses.ResponseNewParamsInputUnion{
|
Input: responses.ResponseNewParamsInputUnion{
|
||||||
OfString: openai.Opt(req.Prompt),
|
OfInputItemList: input,
|
||||||
},
|
},
|
||||||
Instructions: openai.Opt("You are an image generation assistant."),
|
Instructions: openai.Opt("You are an image generation assistant."),
|
||||||
Tools: []responses.ToolUnionParam{tool},
|
Tools: []responses.ToolUnionParam{tool},
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package oauthprovider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/openai/openai-go/v3/responses"
|
"github.com/openai/openai-go/v3/responses"
|
||||||
|
|
@ -51,6 +53,22 @@ func TestBuildCodexImageParams(t *testing.T) {
|
||||||
if params.Model != "gpt-5.4" {
|
if params.Model != "gpt-5.4" {
|
||||||
t.Fatalf("request model = %q, want gpt-5.4", params.Model)
|
t.Fatalf("request model = %q, want gpt-5.4", params.Model)
|
||||||
}
|
}
|
||||||
|
if params.Input.OfString.Valid() {
|
||||||
|
t.Fatalf("input uses string form, want structured message input")
|
||||||
|
}
|
||||||
|
if len(params.Input.OfInputItemList) != 1 {
|
||||||
|
t.Fatalf("input item count = %d, want 1", len(params.Input.OfInputItemList))
|
||||||
|
}
|
||||||
|
data, err := json.Marshal(params)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("marshal params: %v", err)
|
||||||
|
}
|
||||||
|
payload := string(data)
|
||||||
|
for _, want := range []string{`"input":[`, `"role":"user"`, `"type":"input_text"`, `"text":"make a tiny icon"`} {
|
||||||
|
if !strings.Contains(payload, want) {
|
||||||
|
t.Fatalf("payload missing %s: %s", want, payload)
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(params.Tools) != 1 || params.Tools[0].OfImageGeneration == nil {
|
if len(params.Tools) != 1 || params.Tools[0].OfImageGeneration == nil {
|
||||||
t.Fatalf("expected one image_generation tool, got %#v", params.Tools)
|
t.Fatalf("expected one image_generation tool, got %#v", params.Tools)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue