feat(api): 火山模型协议 - 接入方舟与即梦图片视频生成并支持 AK/SK 凭证
This commit is contained in:
1 parent
9ad2fb1b99
commit
c33e05ff63
29 files changed
+1739
-310
No files matched your search
@@ -8,65 +8,30 @@ import (
|
||||
"infinite-canvas/backend/internal/model"
|
||||
)
|
||||
|
||||
func TestChannelFromRequestStoresInterfaceType(t *testing.T) {
|
||||
func TestChannelFromRequestStoresConnectionWithoutDefaultProtocol(t *testing.T) {
|
||||
t.Setenv("CANVAS_ALLOW_PRIVATE_UPSTREAMS", "true")
|
||||
server := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
|
||||
defer server.Close()
|
||||
|
||||
channel, err := channelFromRequest(ChannelRequest{
|
||||
Name: "NewAPI 渠道 1",
|
||||
Name: "混合模型渠道",
|
||||
BaseURL: server.URL + "/v1",
|
||||
APIKey: "secret",
|
||||
InterfaceType: "newapi-channel-1",
|
||||
APIKey: "access-key",
|
||||
SecretKey: "secret-key",
|
||||
ConcurrencyLimit: intPtr(6),
|
||||
Models: []string{"seedance-2.0"},
|
||||
}, model.ModelChannel{})
|
||||
if err != nil {
|
||||
t.Fatalf("channelFromRequest() error = %v", err)
|
||||
}
|
||||
if channel.InterfaceType != model.ChannelInterfaceNewAPIChannel1 {
|
||||
t.Fatalf("InterfaceType = %q", channel.InterfaceType)
|
||||
}
|
||||
if channel.APIFormat != "openai" {
|
||||
t.Fatalf("APIFormat = %q, want openai", channel.APIFormat)
|
||||
}
|
||||
if channel.ConcurrencyLimit != 6 {
|
||||
t.Fatalf("ConcurrencyLimit = %d, want 6", channel.ConcurrencyLimit)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannelFromRequestStoresXAIVideoInterfaceType(t *testing.T) {
|
||||
t.Setenv("CANVAS_ALLOW_PRIVATE_UPSTREAMS", "true")
|
||||
server := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
|
||||
defer server.Close()
|
||||
|
||||
channel, err := channelFromRequest(ChannelRequest{
|
||||
Name: "xAI Video",
|
||||
BaseURL: server.URL + "/v1",
|
||||
APIKey: "secret",
|
||||
InterfaceType: "xai-video",
|
||||
Models: []string{"grok-imagine-video-1.5"},
|
||||
}, model.ModelChannel{})
|
||||
if err != nil {
|
||||
t.Fatalf("channelFromRequest() error = %v", err)
|
||||
}
|
||||
if channel.InterfaceType != model.ChannelInterfaceXAIVideo {
|
||||
t.Fatalf("InterfaceType = %q", channel.InterfaceType)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannelFromRequestUsesGeminiAuthForVeo(t *testing.T) {
|
||||
channel, err := channelFromRequest(ChannelRequest{
|
||||
Name: "Gemini Veo",
|
||||
BaseURL: "https://generativelanguage.googleapis.com",
|
||||
APIKey: "key",
|
||||
InterfaceType: "gemini-veo",
|
||||
}, model.ModelChannel{})
|
||||
if err != nil {
|
||||
t.Fatalf("channelFromRequest() error = %v", err)
|
||||
}
|
||||
if channel.InterfaceType != model.ChannelInterfaceGeminiVeo || channel.APIFormat != "gemini" {
|
||||
t.Fatalf("channel = %#v", channel)
|
||||
if channel.APIKey != "access-key" || channel.SecretKey != "secret-key" {
|
||||
t.Fatal("channel credentials were not stored")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,21 +43,14 @@ func TestMergeChannelRequestSupportsEnabledOnlyPatch(t *testing.T) {
|
||||
APIFormat: "openai",
|
||||
ModelsJSON: `["custom-video"]`,
|
||||
})
|
||||
if req.Name != "Video" || req.BaseURL != "https://example.com/v1" || req.InterfaceType != "newapi" || len(req.Models) != 1 {
|
||||
if req.Name != "Video" || req.BaseURL != "https://example.com/v1" || len(req.Models) != 1 {
|
||||
t.Fatalf("mergeChannelRequest() = %#v", req)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannelFromRequestRejectsUnknownInterfaceType(t *testing.T) {
|
||||
_, err := channelFromRequest(ChannelRequest{Name: "Bad", BaseURL: "https://example.com/v1", InterfaceType: "unknown"}, model.ModelChannel{})
|
||||
if err == nil {
|
||||
t.Fatal("channelFromRequest() error = nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannelFromRequestRejectsInvalidConcurrencyLimit(t *testing.T) {
|
||||
for _, limit := range []int{0, 1000} {
|
||||
_, err := channelFromRequest(ChannelRequest{Name: "Bad", BaseURL: "https://example.com/v1", InterfaceType: "newapi", ConcurrencyLimit: &limit}, model.ModelChannel{})
|
||||
_, err := channelFromRequest(ChannelRequest{Name: "Bad", BaseURL: "https://example.com/v1", ConcurrencyLimit: &limit}, model.ModelChannel{})
|
||||
if err == nil {
|
||||
t.Fatalf("channelFromRequest() concurrencyLimit = %d, error = nil", limit)
|
||||
}
|
||||
@@ -108,7 +66,7 @@ func TestRuntimeConcurrencyUsesEnvironmentFallback(t *testing.T) {
|
||||
}
|
||||
|
||||
useGlobal := true
|
||||
channel, err := channelFromRequest(ChannelRequest{Name: "Global", BaseURL: "https://example.com/v1", InterfaceType: "newapi", UseGlobalConcurrency: &useGlobal}, model.ModelChannel{ConcurrencyLimit: 4})
|
||||
channel, err := channelFromRequest(ChannelRequest{Name: "Global", BaseURL: "https://example.com/v1", UseGlobalConcurrency: &useGlobal}, model.ModelChannel{ConcurrencyLimit: 4})
|
||||
if err != nil || channel.ConcurrencyLimit != 0 {
|
||||
t.Fatalf("global concurrency channel = %#v, error = %v", channel, err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user