diff --git a/common/constants.go b/common/constants.go index 3ca6ba90..5dc7623e 100644 --- a/common/constants.go +++ b/common/constants.go @@ -54,6 +54,7 @@ var QuotaForNewUser = 0 var ChannelDisableThreshold = 5.0 var AutomaticDisableChannelEnabled = false var QuotaRemindThreshold = 1000 +var PreConsumedQuota = 500 var RootUserEmail = "" diff --git a/controller/relay.go b/controller/relay.go index 99225a9d..590842f4 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -128,7 +128,8 @@ func relayHelper(c *gin.Context) error { model_ = strings.TrimSuffix(model_, "-0314") fullRequestURL = fmt.Sprintf("%s/openai/deployments/%s/%s", baseURL, model_, task) } - preConsumedQuota := 500 // TODO: make this configurable, take ratio into account + ratio := common.GetModelRatio(textRequest.Model) + preConsumedQuota := int(float64(common.PreConsumedQuota) * ratio) if consumeQuota { err := model.PreConsumeTokenQuota(tokenId, preConsumedQuota) if err != nil { @@ -184,7 +185,6 @@ func relayHelper(c *gin.Context) error { } else { quota = textResponse.Usage.PromptTokens + textResponse.Usage.CompletionTokens*completionRatio } - ratio := common.GetModelRatio(textRequest.Model) quota = int(float64(quota) * ratio) quotaDelta := quota - preConsumedQuota err := model.PostConsumeTokenQuota(tokenId, quotaDelta) diff --git a/model/option.go b/model/option.go index 14162420..0a29910d 100644 --- a/model/option.go +++ b/model/option.go @@ -55,6 +55,7 @@ func InitOptionMap() { common.OptionMap["TurnstileSecretKey"] = "" common.OptionMap["QuotaForNewUser"] = strconv.Itoa(common.QuotaForNewUser) common.OptionMap["QuotaRemindThreshold"] = strconv.Itoa(common.QuotaRemindThreshold) + common.OptionMap["PreConsumedQuota"] = strconv.Itoa(common.PreConsumedQuota) common.OptionMap["ModelRatio"] = common.ModelRatio2JSONString() common.OptionMap["TopUpLink"] = common.TopUpLink common.OptionMapRWMutex.Unlock() @@ -159,6 +160,8 @@ func updateOptionMap(key string, value string) (err error) { common.QuotaForNewUser, _ = strconv.Atoi(value) case "QuotaRemindThreshold": common.QuotaRemindThreshold, _ = strconv.Atoi(value) + case "PreConsumedQuota": + common.PreConsumedQuota, _ = strconv.Atoi(value) case "ModelRatio": err = common.UpdateModelRatioByJSONString(value) case "TopUpLink": diff --git a/web/src/components/SystemSetting.js b/web/src/components/SystemSetting.js index d71d8815..f64391a9 100644 --- a/web/src/components/SystemSetting.js +++ b/web/src/components/SystemSetting.js @@ -28,6 +28,7 @@ const SystemSetting = () => { RegisterEnabled: '', QuotaForNewUser: 0, QuotaRemindThreshold: 0, + PreConsumedQuota: 0, ModelRatio: '', TopUpLink: '', AutomaticDisableChannelEnabled: '', @@ -98,6 +99,7 @@ const SystemSetting = () => { name === 'TurnstileSecretKey' || name === 'QuotaForNewUser' || name === 'QuotaRemindThreshold' || + name === 'PreConsumedQuota' || name === 'ModelRatio' || name === 'TopUpLink' ) { @@ -119,6 +121,9 @@ const SystemSetting = () => { if (originInputs['QuotaRemindThreshold'] !== inputs.QuotaRemindThreshold) { await updateOption('QuotaRemindThreshold', inputs.QuotaRemindThreshold); } + if (originInputs['PreConsumedQuota'] !== inputs.PreConsumedQuota) { + await updateOption('PreConsumedQuota', inputs.PreConsumedQuota); + } if (originInputs['ModelRatio'] !== inputs.ModelRatio) { if (!verifyJSON(inputs.ModelRatio)) { showError('模型倍率不是合法的 JSON 字符串'); @@ -272,7 +277,7 @@ const SystemSetting = () => {
运营设置
- + { min='0' placeholder='低于此额度时将发送邮件提醒用户' /> +