fix(canvas): 媒体生成 - 修复已有图片引用和图片音频视频模型匹配
This commit is contained in:
@@ -950,6 +950,58 @@ func TestRunImageTaskOmitsAutomaticQualityAndSize(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunOpenAIImageTaskUsesMultipartEditContract(t *testing.T) {
|
||||
t.Setenv("CANVAS_ALLOW_PRIVATE_UPSTREAMS", "true")
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/v1/images/edits" {
|
||||
t.Errorf("path = %q, want /v1/images/edits", r.URL.Path)
|
||||
}
|
||||
if contentType := r.Header.Get("Content-Type"); !strings.HasPrefix(contentType, "multipart/form-data;") {
|
||||
t.Errorf("Content-Type = %q, want multipart/form-data", contentType)
|
||||
}
|
||||
if err := r.ParseMultipartForm(2 << 20); err != nil {
|
||||
t.Fatalf("ParseMultipartForm() error = %v", err)
|
||||
}
|
||||
if r.FormValue("model") != "gpt-image-2-high" || r.FormValue("prompt") != "make the reference clearer" || r.FormValue("n") != "1" {
|
||||
t.Fatalf("form values = model:%q prompt:%q n:%q", r.FormValue("model"), r.FormValue("prompt"), r.FormValue("n"))
|
||||
}
|
||||
if r.FormValue("response_format") != "b64_json" || r.FormValue("output_format") != "png" || r.FormValue("size") != "1024x1024" {
|
||||
t.Fatalf("format values = response_format:%q output_format:%q size:%q", r.FormValue("response_format"), r.FormValue("output_format"), r.FormValue("size"))
|
||||
}
|
||||
file, header, err := r.FormFile("image")
|
||||
if err != nil {
|
||||
t.Fatalf("FormFile(image) error = %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
content, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadAll(image) error = %v", err)
|
||||
}
|
||||
if header.Filename != "reference-reference.png" || string(content) != "hello" {
|
||||
t.Fatalf("image = filename:%q content:%q", header.Filename, string(content))
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"data":[{"b64_json":"aGVsbG8="}]}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
profile := DefaultImageCapabilityConfig("openai-image", "gpt-image-2-high")
|
||||
result, err := runImageTask(context.Background(), canvasGenerationInput{
|
||||
Mode: "image",
|
||||
Prompt: "make the reference clearer",
|
||||
Config: providerConfig{BaseURL: server.URL, APIKey: "key", Model: "gpt-image-2-high", InterfaceType: "openai-image", Size: "1024x1024"},
|
||||
ImageCapability: profile,
|
||||
ReferenceImages: []providerMedia{{Name: "reference.png", Type: "image/png", DataURL: testReferenceImageDataURL}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("runImageTask() error = %v", err)
|
||||
}
|
||||
images, _ := result["images"].([]map[string]string)
|
||||
if len(images) != 1 || images[0]["dataUrl"] != "data:image/png;base64,aGVsbG8=" {
|
||||
t.Fatalf("images = %#v", result["images"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunGrokImageTaskUsesJSONEditContract(t *testing.T) {
|
||||
t.Setenv("CANVAS_ALLOW_PRIVATE_UPSTREAMS", "true")
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user