feat(canvas): 模型选择 - 支持彩色展示标签并优化目录与积分交互
This commit is contained in:
1 parent
d5ff22258e
commit
b8eefdad70
31 files changed
+410
-63
No files matched your search
@@ -18,6 +18,7 @@ func TestChannelModelLabelSaveAndCatalogPreserveChannelIdentity(t *testing.T) {
|
||||
ModelKey: "gpt-test", ProviderModelKey: "upstream-text", DisplayName: "GPT Test", Icon: "OpenAI",
|
||||
ChannelLabel: " 优惠渠道-993 ", Capability: "text", Protocol: string(model.ChannelInterfaceChatCompletion),
|
||||
Description: " 适合分镜脚本,请先确认输入要求。 ",
|
||||
Tags: []model.ChannelModelTag{{Text: " 限时特价 ", Color: "purple"}, {Text: "官方1折", Color: "gold"}},
|
||||
CapabilityConfig: DefaultModelCapabilityConfigForModel(string(model.ChannelInterfaceChatCompletion), "gpt-test"),
|
||||
PriceTiers: []ChannelModelPriceTierRequest{{BillingMode: "fixed_request", UnitPriceMicrocredits: 300000, PriceConfigured: true, Enabled: &enabled}},
|
||||
Enabled: &enabled,
|
||||
@@ -40,6 +41,9 @@ func TestChannelModelLabelSaveAndCatalogPreserveChannelIdentity(t *testing.T) {
|
||||
t.Fatalf("stored channel model: %#v", stored)
|
||||
}
|
||||
legacy := publicChannel(channel, false, []model.ChannelModel{*saved})
|
||||
if len(stored.Tags) != 2 || stored.Tags[0].Text != "限时特价" || stored.Tags[1].Color != "gold" || len(legacy.ModelCosts[0].Tags) != 2 {
|
||||
t.Fatalf("tags not persisted or projected: %#v", stored.Tags)
|
||||
}
|
||||
if stored.Description != "适合分镜脚本,请先确认输入要求。" || legacy.ModelCosts[0].Description != stored.Description {
|
||||
t.Fatal("model description was not persisted or projected")
|
||||
}
|
||||
@@ -55,6 +59,9 @@ func TestChannelModelLabelSaveAndCatalogPreserveChannelIdentity(t *testing.T) {
|
||||
t.Fatalf("catalog: %#v, %v", catalog, err)
|
||||
}
|
||||
for _, channel := range catalog.Channels {
|
||||
if len(channel.Models) != 1 || len(channel.Models[0].Tags) != 2 || channel.Models[0].Tags[0].Text != "限时特价" {
|
||||
t.Fatalf("catalog lost tags: %#v", channel)
|
||||
}
|
||||
if len(channel.Models) == 1 && channel.Models[0].Description != "适合分镜脚本,请先确认输入要求。" {
|
||||
t.Fatal("catalog lost model description")
|
||||
}
|
||||
@@ -62,6 +69,15 @@ func TestChannelModelLabelSaveAndCatalogPreserveChannelIdentity(t *testing.T) {
|
||||
t.Fatalf("catalog lost label or pricing: %#v", channel)
|
||||
}
|
||||
}
|
||||
invalidTags := request
|
||||
invalidTags.Tags = []model.ChannelModelTag{{Text: "限时特价", Color: "invalid"}}
|
||||
if _, err := svc.SaveAdminChannelModel(admin, "channel-a", firstID, invalidTags); err == nil {
|
||||
t.Fatal("accepted invalid tag color")
|
||||
}
|
||||
var unchanged model.ChannelModel
|
||||
if err := db.First(&unchanged, "id = ?", firstID).Error; err != nil || len(unchanged.Tags) != 2 || unchanged.Tags[0].Color != "purple" {
|
||||
t.Fatalf("invalid write changed persisted tags: %#v, %v", unchanged.Tags, err)
|
||||
}
|
||||
request.ChannelLabel = strings.Repeat("字", 81)
|
||||
if _, err := svc.SaveAdminChannelModel(admin, "channel-a", firstID, request); err == nil {
|
||||
t.Fatal("accepted oversized channel label")
|
||||
@@ -76,10 +92,15 @@ func TestChannelModelLabelSaveAndCatalogPreserveChannelIdentity(t *testing.T) {
|
||||
t.Fatalf("rejected valid 500-character description: %v", err)
|
||||
}
|
||||
request.Description = " "
|
||||
request.Tags = []model.ChannelModelTag{}
|
||||
updated, err := svc.SaveAdminChannelModel(admin, "channel-a", firstID, request)
|
||||
if err != nil || updated.ChannelLabel != "" || updated.Description != "" || updated.ID != firstID {
|
||||
t.Fatalf("label clearing changed identity: %#v, %v", updated, err)
|
||||
}
|
||||
var cleared model.ChannelModel
|
||||
if err := db.First(&cleared, "id = ?", firstID).Error; err != nil || len(cleared.Tags) != 0 {
|
||||
t.Fatalf("tags not cleared: %#v %v", cleared.Tags, err)
|
||||
}
|
||||
if _, err := svc.SaveAdminChannelModel(&model.User{ID: "user", Role: model.UserRoleUser}, "channel-a", firstID, request); err == nil {
|
||||
t.Fatal("non-admin changed channel label")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user