功能增加
This commit is contained in:
1 parent
b340fc7ad7
commit
f1993eb388
69 files changed
+2243
-162
No files matched your search
@@ -27,6 +27,7 @@ func TestHTTPAdaptersMapRequestsAndResponses(t *testing.T) {
|
||||
{"evolink", NewEvoLink(Config{BaseURL: "https://e.test", APIKey: "secret", Model: "gpt-image-2"}, nil), "/v1/images/generations", "/v1/tasks/task-1", `{"id":"task-1","status":"completed","results":[{"url":"https://cdn.test/a.png"}]}`},
|
||||
{"bailian", NewBailian(Config{BaseURL: "https://b.test", APIKey: "secret", Model: "wan"}, nil), "/api/v1/services/aigc/image-generation/generation", "/api/v1/tasks/task-1", `{"output":{"task_id":"task-1","task_status":"SUCCEEDED","results":[{"url":"https://cdn.test/a.png"}]}}`},
|
||||
{"seedance", NewSeedance(Config{BaseURL: "https://s.test/api/v3", APIKey: "secret", Model: "seed"}, nil), "/api/v3/contents/generations/tasks", "/api/v3/contents/generations/tasks/task-1", `{"id":"task-1","status":"succeeded","content":{"video_url":"https://cdn.test/a.mp4"}}`},
|
||||
{"minimax", NewMinimax(Config{BaseURL: "https://m.test", APIKey: "secret", Model: MinimaxH3Model}, nil), "/v2/video_generation", "/v2/query/video_generation/task-1", `{"task":{"id":"task-1","status":"succeeded","content":{"url":"https://cdn.test/a.mp4"}}}`},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@@ -52,6 +53,8 @@ func TestHTTPAdaptersMapRequestsAndResponses(t *testing.T) {
|
||||
a.client = client
|
||||
case *Seedance:
|
||||
a.client = client
|
||||
case *Minimax:
|
||||
a.client = client
|
||||
}
|
||||
submitted, err := tt.adapter.Submit(context.Background(), Request{Capability: "image.generate", Prompt: "hello"})
|
||||
if err != nil || submitted.TaskID != "task-1" {
|
||||
@@ -65,6 +68,50 @@ func TestHTTPAdaptersMapRequestsAndResponses(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMinimaxH3PayloadAndUsageMatchOfficialV2Contract(t *testing.T) {
|
||||
var calls int
|
||||
client := roundTripFunc(func(request *http.Request) (*http.Response, error) {
|
||||
calls++
|
||||
if request.Header.Get("Authorization") != "Bearer secret" {
|
||||
t.Fatalf("authorization=%q", request.Header.Get("Authorization"))
|
||||
}
|
||||
if calls == 1 {
|
||||
var body map[string]any
|
||||
if err := json.NewDecoder(request.Body).Decode(&body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
content := body["content"].([]any)
|
||||
image := content[1].(map[string]any)
|
||||
imageURL := image["image_url"].(map[string]any)
|
||||
if body["model"] != MinimaxH3Model || body["resolution"] != "2K" || body["duration"] != float64(8) || body["ratio"] != "adaptive" || body["aigc_watermark"] != false || len(content) != 2 || image["role"] != "first_frame" || imageURL["url"] != "https://cdn.test/first.png" {
|
||||
t.Fatalf("body=%#v", body)
|
||||
}
|
||||
return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(`{"task_id":"task-h3"}`)), Header: http.Header{}}, nil
|
||||
}
|
||||
return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(`{"task":{"id":"task-h3","model":"MiniMax-H3","status":"succeeded","content":{"url":"https://cdn.test/h3.mp4"},"resolution":"2K","duration":8,"usage":{"total_seconds":8,"input_seconds":0,"output_seconds":8,"input_image_count":1,"completion_tokens":1234},"ratio":"16:9"}}`)), Header: http.Header{}}, nil
|
||||
})
|
||||
adapter := NewMinimax(Config{BaseURL: "https://m.test", APIKey: "secret", Model: MinimaxH3Model}, client)
|
||||
submitted, err := adapter.Submit(context.Background(), Request{
|
||||
Capability: "video.generate", Prompt: "animate", Materials: []Material{{URL: "https://cdn.test/first.png", Type: MaterialImage}},
|
||||
Settings: map[string]any{"resolution": "2K", "duration": float64(8), "ratio": "adaptive"},
|
||||
})
|
||||
if err != nil || submitted.TaskID != "task-h3" || submitted.Status != StatusQueued {
|
||||
t.Fatalf("submitted=%#v err=%v", submitted, err)
|
||||
}
|
||||
queried, err := adapter.Query(context.Background(), submitted.TaskID)
|
||||
if err != nil || queried.Status != StatusSucceeded || !reflect.DeepEqual(queried.OutputURLs, []string{"https://cdn.test/h3.mp4"}) || queried.Usage["outputSeconds"] != 8 || queried.Usage["inputImageCount"] != 1 {
|
||||
t.Fatalf("queried=%#v err=%v", queried, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMinimaxErrorDiagnosticsExtractSafeNumericCode(t *testing.T) {
|
||||
raw := []byte(`{"type":"error","error":{"type":"insufficient_balance_error","message":"insufficient balance (1008)","http_code":"402"},"request_id":"request-safe"}`)
|
||||
code, requestID, errorType := inspectHTTPProviderFailure(raw, http.Header{})
|
||||
if code != "1008" || requestID != "request-safe" || errorType != "insufficient_balance_error" {
|
||||
t.Fatalf("diagnostics=%q/%q/%q", code, requestID, errorType)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBailianOnlyEnablesAsyncModeWhenSubmitting(t *testing.T) {
|
||||
var requests []*http.Request
|
||||
client := roundTripFunc(func(request *http.Request) (*http.Response, error) {
|
||||
|
||||
Reference in new issue
Block a user