fix(channel): 修复前台自定义渠道模型配置抽屉空白死锁,并在启动时保护管理员能力配置 (#360)
Co-authored-by: Danborad <danborad@github.com>
This commit is contained in:
@@ -296,6 +296,9 @@ func validateChannelModelTierCapabilities(tiers []model.ChannelModelPriceTier, r
|
||||
if tier.VideoSeconds == 0 {
|
||||
continue
|
||||
}
|
||||
if !videoDurationSupported(config.Video) {
|
||||
continue
|
||||
}
|
||||
if config.Video.Duration.Selection == "enum" && !durationSupported[tier.VideoSeconds] {
|
||||
return BadAuthRequest(fmt.Sprintf("价格档时长 %d 秒不在该视频模型支持范围内", tier.VideoSeconds))
|
||||
}
|
||||
@@ -742,30 +745,26 @@ func (s *Service) syncInitialChannelModels(channel *model.ModelChannel, names []
|
||||
}
|
||||
desired[name] = true
|
||||
if item := byKey[name]; item != nil {
|
||||
if !item.Enabled {
|
||||
item.Enabled = true
|
||||
item.PriceVersion++
|
||||
if err := s.repo.SaveChannelModel(item); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
modelID, idErr := s.repo.NextPrefixedID("MODEL")
|
||||
if idErr != nil {
|
||||
return idErr
|
||||
}
|
||||
item := model.ChannelModel{ID: modelID, ChannelID: channel.ID, ModelKey: name, DisplayName: name, BillingMode: "fixed_request", Enabled: false, PriceVersion: 1}
|
||||
item := model.ChannelModel{ID: modelID, ChannelID: channel.ID, ModelKey: name, DisplayName: name, BillingMode: "fixed_request", Enabled: false, PriceConfigured: false, UnitPriceMicrocredits: 0, PriceVersion: 1}
|
||||
if err := s.repo.SaveChannelModel(&item); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for index := range existing {
|
||||
if existing[index].Enabled && !desired[existing[index].ModelKey] {
|
||||
if !desired[existing[index].ModelKey] {
|
||||
changed := existing[index].Enabled
|
||||
existing[index].Enabled = false
|
||||
existing[index].PriceVersion++
|
||||
if err := s.repo.SaveChannelModel(&existing[index]); err != nil {
|
||||
return err
|
||||
if changed {
|
||||
existing[index].PriceVersion++
|
||||
if err := s.repo.SaveChannelModel(&existing[index]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ type ParameterSupport struct {
|
||||
type VideoCapabilityConfig struct {
|
||||
References VideoReferenceConfig `json:"references"`
|
||||
Duration VideoDurationConfig `json:"duration"`
|
||||
DurationSupported *bool `json:"durationSupported,omitempty"`
|
||||
Ratios []string `json:"ratios"`
|
||||
DefaultRatio string `json:"defaultRatio"`
|
||||
Resolutions []string `json:"resolutions"`
|
||||
@@ -109,6 +110,10 @@ func DefaultModelCapabilityConfig(protocol string) *ModelCapabilityConfig {
|
||||
return DefaultModelCapabilityConfigForModel(protocol, "")
|
||||
}
|
||||
|
||||
func videoDurationSupported(value *VideoCapabilityConfig) bool {
|
||||
return value == nil || value.DurationSupported == nil || *value.DurationSupported
|
||||
}
|
||||
|
||||
func DefaultImageCapabilityConfig(protocol string, modelName string) *ImageCapabilityConfig {
|
||||
image := &ImageCapabilityConfig{
|
||||
References: ImageReferenceConfig{PromptMaxChars: 32000, MaxImages: 16, MaxImageBytes: 30 * 1024 * 1024, MaskSupported: true},
|
||||
|
||||
Reference in New Issue
Block a user