diff --git a/common/constants.go b/common/constants.go index e99e9a05..658be574 100644 --- a/common/constants.go +++ b/common/constants.go @@ -48,6 +48,7 @@ var TurnstileSiteKey = "" var TurnstileSecretKey = "" var QuotaForNewUser = 100 +var BytesNumber2Quota = 0.8 const ( RoleGuestUser = 0 diff --git a/controller/relay.go b/controller/relay.go index e31dcd9b..be64d791 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -110,7 +110,7 @@ func relayHelper(c *gin.Context) error { if consumeQuota { quota := 0 if isStream { - quota = int(float64(len(streamResponseText)) * 0.8) + quota = int(float64(len(streamResponseText)) * common.BytesNumber2Quota) } else { quota = textResponse.Usage.TotalTokens } diff --git a/model/option.go b/model/option.go index 840ae000..47ed42f9 100644 --- a/model/option.go +++ b/model/option.go @@ -47,6 +47,7 @@ func InitOptionMap() { common.OptionMap["TurnstileSiteKey"] = "" common.OptionMap["TurnstileSecretKey"] = "" common.OptionMap["QuotaForNewUser"] = strconv.Itoa(common.QuotaForNewUser) + common.OptionMap["BytesNumber2Quota"] = strconv.FormatFloat(common.BytesNumber2Quota, 'f', -1, 64) common.OptionMap["TopUpLink"] = common.TopUpLink common.OptionMapRWMutex.Unlock() options, _ := AllOption() @@ -135,6 +136,8 @@ func updateOptionMap(key string, value string) { common.TurnstileSecretKey = value case "QuotaForNewUser": common.QuotaForNewUser, _ = strconv.Atoi(value) + case "BytesNumber2Quota": + common.BytesNumber2Quota, _ = strconv.ParseFloat(value, 64) case "TopUpLink": common.TopUpLink = value } diff --git a/web/src/components/SystemSetting.js b/web/src/components/SystemSetting.js index 124f4745..f05c8a4a 100644 --- a/web/src/components/SystemSetting.js +++ b/web/src/components/SystemSetting.js @@ -25,6 +25,7 @@ const SystemSetting = () => { TurnstileSecretKey: '', RegisterEnabled: '', QuotaForNewUser: 0, + BytesNumber2Quota: 0.8, TopUpLink: '' }); let originInputs = {}; @@ -90,6 +91,7 @@ const SystemSetting = () => { name === 'TurnstileSiteKey' || name === 'TurnstileSecretKey' || name === 'QuotaForNewUser' || + name === 'BytesNumber2Quota' || name === 'TopUpLink' ) { setInputs((inputs) => ({ ...inputs, [name]: value })); @@ -107,6 +109,9 @@ const SystemSetting = () => { if (originInputs['QuotaForNewUser'] !== inputs.QuotaForNewUser) { await updateOption('QuotaForNewUser', inputs.QuotaForNewUser); } + if (originInputs['BytesNumber2Quota'] !== inputs.BytesNumber2Quota) { + await updateOption('BytesNumber2Quota', inputs.BytesNumber2Quota); + } if (originInputs['TopUpLink'] !== inputs.TopUpLink) { await updateOption('TopUpLink', inputs.TopUpLink); } @@ -255,6 +260,17 @@ const SystemSetting = () => { min='0' placeholder='例如:100' /> +