mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-11 14:41:21 +00:00
73 lines
2.7 KiB
Go
73 lines
2.7 KiB
Go
package plugins_test
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/QuantumNous/new-api/common"
|
|
"github.com/QuantumNous/new-api/model"
|
|
"github.com/QuantumNous/new-api/pkg/jsplugin"
|
|
builtinplugins "github.com/QuantumNous/new-api/plugins"
|
|
"github.com/QuantumNous/new-api/relay/channel"
|
|
taskplugin "github.com/QuantumNous/new-api/relay/channel/task/jsplugin"
|
|
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestHailuoResponsesProtocol(t *testing.T) {
|
|
testVideoResponsesProtocol(t, videoResponsesTestCase{
|
|
pluginKey: "hailuo",
|
|
model: "MiniMax-Hailuo-2.3",
|
|
requestBody: map[string]any{
|
|
"model": "MiniMax-Hailuo-2.3",
|
|
"input": []any{map[string]any{"role": "user", "content": []any{
|
|
map[string]any{"type": "input_text", "text": "ocean at sunset"},
|
|
map[string]any{"type": "input_image", "image_url": "https://cdn.example/frame.png"},
|
|
}}},
|
|
"seconds": 10,
|
|
"size": "1920x1080",
|
|
},
|
|
wantAction: "image_to_video",
|
|
wantRequest: map[string]any{
|
|
"model": "MiniMax-Hailuo-2.3",
|
|
"prompt": "ocean at sunset",
|
|
"images": []any{"https://cdn.example/frame.png"},
|
|
"duration": float64(10),
|
|
"size": "1920x1080",
|
|
"metadata": map[string]any{"first_frame_image": "https://cdn.example/frame.png"},
|
|
},
|
|
wantUsageKeys: []string{"resolution", "seconds"},
|
|
wantVendorName: "hailuo",
|
|
})
|
|
}
|
|
|
|
func TestHailuoArtifactContentProxy(t *testing.T) {
|
|
source, err := builtinplugins.Source("hailuo")
|
|
require.NoError(t, err)
|
|
plugin, err := jsplugin.NewRegistry().RegisterFactory(source, jsplugin.Options{Key: "hailuo"})
|
|
require.NoError(t, err)
|
|
adaptor := taskplugin.New(plugin)
|
|
adaptor.Init(&relaycommon.RelayInfo{
|
|
ChannelMeta: &relaycommon.ChannelMeta{
|
|
ApiKey: "test-ak",
|
|
ChannelBaseUrl: "https://api.minimax.example",
|
|
},
|
|
})
|
|
data, err := common.Marshal(map[string]any{"file_id": "file/with space"})
|
|
require.NoError(t, err)
|
|
task := &model.Task{TaskID: "task-public", Status: model.TaskStatusSuccess, Data: data}
|
|
|
|
artifacts, err := adaptor.ListArtifacts(task)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, []channel.TaskArtifact{{Key: "video", Type: "video", MimeType: "video/mp4"}}, artifacts)
|
|
|
|
descriptor, err := adaptor.BuildContentRequest(task, "video", channel.TaskArtifactClientRequest{Method: http.MethodHead})
|
|
require.NoError(t, err)
|
|
require.NotNil(t, descriptor)
|
|
assert.Equal(t, "https://api.minimax.example/v1/files/download?file_id=file%2Fwith%20space", descriptor.URL)
|
|
assert.Equal(t, http.MethodHead, descriptor.Method)
|
|
assert.Equal(t, map[string]string{"Accept": "video/*", "Authorization": "Bearer test-ak"}, descriptor.Headers)
|
|
assert.False(t, descriptor.Credentialless)
|
|
}
|