ai去特征增加开关

This commit is contained in:
2026-07-10 00:13:09 +08:00
parent 6d6bd2a638
commit 6a3588b35b
4 changed files with 40 additions and 8 deletions
+7
View File
@@ -51,6 +51,7 @@ type CreditSettings struct {
// DeAISettings is the per-tier surcharge (积分) for the 去AI特征 option on the
// 画图台 — charged on top of the model's image price when the toggle is on.
type DeAISettings struct {
Enabled bool `json:"enabled"`
Price1K int `json:"price_1k"`
Price2K int `json:"price_2k"`
Price4K int `json:"price_4k"`
@@ -343,6 +344,10 @@ func (s *AppSettingsService) TestProxy(ctx context.Context, proxy string) (map[s
}
func (s *AppSettingsService) DeAI(ctx context.Context) (*DeAISettings, error) {
enabledRaw, err := s.settings.GetValue(ctx, "deai.enabled")
if err != nil {
return nil, err
}
p1Raw, err := s.settings.GetValue(ctx, "deai.price_1k")
if err != nil {
return nil, err
@@ -356,6 +361,7 @@ func (s *AppSettingsService) DeAI(ctx context.Context) (*DeAISettings, error) {
return nil, err
}
return &DeAISettings{
Enabled: parseBoolSetting(enabledRaw, false),
Price1K: clampNonNegative(parseIntSetting(p1Raw, 1)),
Price2K: clampNonNegative(parseIntSetting(p2Raw, 2)),
Price4K: clampNonNegative(parseIntSetting(p4Raw, 3)),
@@ -364,6 +370,7 @@ func (s *AppSettingsService) DeAI(ctx context.Context) (*DeAISettings, error) {
func (s *AppSettingsService) SaveDeAI(ctx context.Context, in DeAISettings) (*DeAISettings, error) {
if err := s.settings.UpsertValues(ctx, map[string]string{
"deai.enabled": strconv.FormatBool(in.Enabled),
"deai.price_1k": strconv.Itoa(clampNonNegative(in.Price1K)),
"deai.price_2k": strconv.Itoa(clampNonNegative(in.Price2K)),
"deai.price_4k": strconv.Itoa(clampNonNegative(in.Price4K)),
+18
View File
@@ -418,6 +418,11 @@ func (s *V1Service) prepareImageExecution(ctx context.Context, principal *APIPri
return nil, err
}
}
// 去AI特征 is gated by a system-settings switch (default off) — drop the
// flag when disabled so no surcharge is charged and no processing runs.
if in.DeAI && !s.deaiEnabled(ctx) {
in.DeAI = false
}
genCtx, cancel := context.WithTimeout(ctx, 8*time.Minute)
defer cancel()
@@ -2879,6 +2884,19 @@ func guessRatio(w, h int) string {
// firstPricedResolution returns the model's lowest priced image tier (1K/2K/4K
// order), or "" if none is priced. Used to rescue a request whose resolution
// the model doesn't support.
// deaiEnabled reports whether the 去AI特征 feature is switched on in system
// settings (default off). When off, an incoming deai flag is ignored entirely.
func (s *V1Service) deaiEnabled(ctx context.Context) bool {
if s.settings == nil {
return false
}
raw, err := s.settings.GetValue(ctx, "deai.enabled")
if err != nil {
return false
}
return parseBoolSetting(raw, false)
}
// deaiSurcharge returns the 去AI特征 surcharge (积分) for an image resolution
// tier, from site settings (defaults: 1K=1, 2K=2, 4K=3).
func (s *V1Service) deaiSurcharge(ctx context.Context, resolution string) float64 {