完善生图5.0的功能
This commit is contained in:
1 parent
88a4268d40
commit
678d213f40
31 files changed
+3281
-107
No files matched your search
@@ -666,6 +666,31 @@ func TestSeedreamPayloadAndSynchronousResponse(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeedreamLayerDecompositionPayloadAndResponseMetadata(t *testing.T) {
|
||||
client := roundTripFunc(func(request *http.Request) (*http.Response, error) {
|
||||
var body map[string]any
|
||||
if err := json.NewDecoder(request.Body).Decode(&body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if body["image"] != "https://in.test/source.png" || body["layer_decomposition"] != true || body["prompt"] != nil || body["optimize_prompt_options"] != nil {
|
||||
t.Fatalf("body=%#v", body)
|
||||
}
|
||||
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(strings.NewReader(`{
|
||||
"data":[
|
||||
{"url":"https://cdn.test/base.jpeg","size":"2048x2048","z_index":0},
|
||||
{"url":"https://cdn.test/title.png","size":"500x100","z_index":1,"name":"标题"}
|
||||
]
|
||||
}`)), Header: http.Header{}}, nil
|
||||
})
|
||||
result, err := NewSeedream(Config{BaseURL: "https://ark.test/api/v3", APIKey: "secret", Model: Seedream50ProModel}, client).Submit(context.Background(), Request{
|
||||
Capability: "image.generate", InputURLs: []string{"https://in.test/source.png"},
|
||||
Settings: map[string]any{"size": "2K", "outputFormat": "jpeg", "layerDecomposition": true},
|
||||
})
|
||||
if err != nil || result.Status != StatusSucceeded || !reflect.DeepEqual(result.OutputURLs, []string{"https://cdn.test/base.jpeg", "https://cdn.test/title.png"}) || !strings.Contains(string(result.Raw), `"z_index":1`) {
|
||||
t.Fatalf("result=%#v err=%v", result, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMockIsDeterministic(t *testing.T) {
|
||||
m := NewMock("fixture")
|
||||
a, _ := m.Submit(context.Background(), Request{Capability: "video.generate", Prompt: "hello"})
|
||||
|
||||
@@ -26,14 +26,21 @@ func NewSeedream(c Config, client HTTPClient) *Seedream {
|
||||
payload: func(r Request) any {
|
||||
payload := map[string]any{
|
||||
"model": requestModel(r, c.Model),
|
||||
"prompt": r.Prompt,
|
||||
"size": seedreamSetting(r.Settings, "size", "1.5K"),
|
||||
"output_format": seedreamSetting(r.Settings, "outputFormat", "png"),
|
||||
"response_format": "url",
|
||||
"watermark": false,
|
||||
"optimize_prompt_options": map[string]any{
|
||||
}
|
||||
if prompt := strings.TrimSpace(r.Prompt); prompt != "" {
|
||||
payload["prompt"] = prompt
|
||||
}
|
||||
layerDecomposition, _ := r.Settings["layerDecomposition"].(bool)
|
||||
if layerDecomposition {
|
||||
payload["layer_decomposition"] = true
|
||||
} else {
|
||||
payload["optimize_prompt_options"] = map[string]any{
|
||||
"mode": seedreamSetting(r.Settings, "optimizeMode", "standard"),
|
||||
},
|
||||
}
|
||||
}
|
||||
switch len(r.InputURLs) {
|
||||
case 0:
|
||||
|
||||
Reference in new issue
Block a user