fix(plugin): 万相3.0视频 - 分辨率大写与上游错误解析(#614)
fix(plugin): 万相3.0视频 - 分辨率大写与上游错误解析
This commit is contained in:
@@ -48,27 +48,43 @@ func providerResponseBusinessFailure(responseBody []byte) (string, string, bool)
|
||||
}
|
||||
|
||||
func providerPayloadBusinessFailure(payload map[string]any) (string, string, bool) {
|
||||
if code, message, failed := providerBusinessFailure(payload); failed {
|
||||
return code, message, true
|
||||
}
|
||||
// DashScope 业务失败在 output 内
|
||||
if output, ok := payload["output"].(map[string]any); ok {
|
||||
return providerBusinessFailure(output)
|
||||
}
|
||||
return "", "", false
|
||||
}
|
||||
|
||||
func providerBusinessFailure(payload map[string]any) (string, string, bool) {
|
||||
if errorValue, ok := payload["error"].(map[string]any); ok {
|
||||
code, message := providerFailureDetails(map[string]any{"error": errorValue})
|
||||
if code != "" || message != "" {
|
||||
return code, message, true
|
||||
}
|
||||
}
|
||||
if !providerBusinessCodeFailed(payload["code"]) {
|
||||
return "", "", false
|
||||
}
|
||||
code, message := providerFailureDetails(payload)
|
||||
return code, message, true
|
||||
}
|
||||
|
||||
func providerBusinessCodeFailed(value any) bool {
|
||||
code := strings.ToLower(strings.TrimSpace(fmt.Sprint(value)))
|
||||
switch code {
|
||||
case "", "0", "success", "succeeded", "ok", "<nil>":
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
code := strings.ToLower(strings.TrimSpace(fmt.Sprint(payload["code"])))
|
||||
if code != "" && code != "0" &&
|
||||
code != "success" && code != "succeeded" &&
|
||||
code != "ok" && code != "<nil>" {
|
||||
code, message := providerFailureDetails(payload)
|
||||
return code, message, true
|
||||
}
|
||||
|
||||
status := strings.ToLower(strings.TrimSpace(fmt.Sprint(payload["task_status"])))
|
||||
switch status {
|
||||
case "failed", "failure", "error", "expired":
|
||||
code, message := providerFailureDetails(payload)
|
||||
if code == "" {
|
||||
code = "task_failed"
|
||||
}
|
||||
return code, message, true
|
||||
}
|
||||
|
||||
return "", "", false
|
||||
}
|
||||
|
||||
func normalizedProviderErrorCode(value any) string {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package app
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProviderFailureDetailsReadsTopLevelModerationError(t *testing.T) {
|
||||
code, message := providerFailureDetails(map[string]any{
|
||||
@@ -59,3 +62,30 @@ func TestProviderPayloadBusinessFailureAcceptsStringSuccessCode(t *testing.T) {
|
||||
t.Fatalf("success payload was marked failed: (%q, %q)", code, message)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderPayloadBusinessFailureReadsNestedOutputFailure(t *testing.T) {
|
||||
code, message, failed := providerPayloadBusinessFailure(map[string]any{
|
||||
"output": map[string]any{
|
||||
"code": "InvalidParameter",
|
||||
"message": "Input should be '1080P', '720P' or '480P': parameters.resolution",
|
||||
"task_id": "e0d8c86d-4939-4f2e-93f7-e2cd10a07d58",
|
||||
"task_status": "FAILED",
|
||||
},
|
||||
"request_id": "c3c98e67-830d-9f1d-8a62-fff019ffa522",
|
||||
})
|
||||
if !failed || code != "InvalidParameter" {
|
||||
t.Fatalf("nested output failure = (%q, %q, %v)", code, message, failed)
|
||||
}
|
||||
if !strings.Contains(message, "parameters.resolution") {
|
||||
t.Fatalf("unexpected message: %q", message)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderPayloadBusinessFailureIgnoresPendingOutput(t *testing.T) {
|
||||
if code, message, failed := providerPayloadBusinessFailure(map[string]any{
|
||||
"output": map[string]any{"task_id": "task-1", "task_status": "PENDING"},
|
||||
"request_id": "req-1",
|
||||
}); failed {
|
||||
t.Fatalf("pending output marked failed: (%q, %q)", code, message)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
func TestDashscopeWan3VideoCreateAndLifecycle(t *testing.T) {
|
||||
adapter := officialPackageAdapter(t, "dashscope-wan3-video.yingce-plugin", "dashscope-wan3-video")
|
||||
create, err := adapter.BuildCreate(context.Background(), RequestContext{Request: GenerationRequest{
|
||||
Model: "wan3.0-video-prime", Prompt: "一只猫在海边奔跑", Duration: 6, AspectRatio: "16:9", Resolution: "1080P",
|
||||
Model: "wan3.0-video-prime", Prompt: "一只猫在海边奔跑", Duration: 6, AspectRatio: "16:9", Resolution: "1080p",
|
||||
GenerateAudio: true, Watermark: true,
|
||||
Inputs: []MediaReference{
|
||||
{URL: "https://cdn.example/audio.mp3", Kind: "audio", Role: "reference_audio", Order: 3},
|
||||
|
||||
Binary file not shown.
@@ -44,7 +44,7 @@
|
||||
| `create.body.model` | `{"$ref":"request.model"}` |
|
||||
| `create.body.input.prompt` | `{"$omitEmpty":{"$ref":"request.prompt"}}` |
|
||||
| `create.body.input.media` | `{"$omitEmpty":{"$coalesce":[{"$ref":"request.providerOptions.dashscope-wan3-video.media"},{"$map":{"from":{"$sortByOrder":{"$ref":"request.inputs"}},"as":"media","in":{"type":{"$coalesce":[{"$ref":"media.role"},{"$if":{"condition":{"$eq":[{"$ref":"media.kind"},"image"]},"then":"reference_image","else":{"$if":{"condition":{"$eq":[{"$ref":"media.kind"},"video"]},"then":"reference_video","else":{"$if":{"condition":{"$eq":[{"$ref":"media.kind"},"audio"]},"then":"reference_audio","else":{"$ref":"media.kind"}}}}}}}]},"url":{"$ref":"media.value"}}}}]}}` |
|
||||
| `create.body.parameters.resolution` | `{"$omitEmpty":{"$ref":"request.resolution"}}` |
|
||||
| `create.body.parameters.resolution` | `{"$omitEmpty":{"$upper":{"$ref":"request.resolution"}}}` |
|
||||
| `create.body.parameters.ratio` | `{"$omitEmpty":{"$ref":"request.aspectRatio"}}` |
|
||||
| `create.body.parameters.duration` | `{"$omitEmpty":{"$ref":"request.duration"}}` |
|
||||
| `create.body.parameters.audio` | `{"$coalesce":[{"$ref":"request.providerOptions.dashscope-wan3-video.audio"},{"$ref":"request.generateAudio"}]}` |
|
||||
@@ -98,7 +98,7 @@
|
||||
"apiVersion": "yingce.plugin/v2",
|
||||
"id": "dashscope-wan3-video",
|
||||
"name": "DashScope Wan 3.0 Video",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.1",
|
||||
"author": "Alibaba Cloud / 影策",
|
||||
"description": "DashScope Wan 3.0 Video 独立请求协议插件。",
|
||||
"documentation": "<当前插件的完整 documentation,由 README.md 与 docs/interface.md 拼接而成;为避免 JSON 递归,此处不重复展开正文。>",
|
||||
@@ -385,7 +385,9 @@
|
||||
"parameters": {
|
||||
"resolution": {
|
||||
"$omitEmpty": {
|
||||
"$ref": "request.resolution"
|
||||
"$upper": {
|
||||
"$ref": "request.resolution"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ratio": {
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user