diff --git a/common/constants.go b/common/constants.go index 658be574dc..635e90fda2 100644 --- a/common/constants.go +++ b/common/constants.go @@ -48,7 +48,11 @@ var TurnstileSiteKey = "" var TurnstileSecretKey = "" var QuotaForNewUser = 100 -var BytesNumber2Quota = 0.8 + +// https://platform.openai.com/docs/models/model-endpoint-compatibility +var RatioGPT3dot5 float64 = 2 +var RatioGPT4 float64 = 30 +var RatioGPT4_32k float64 = 60 const ( RoleGuestUser = 0 diff --git a/controller/relay.go b/controller/relay.go index 692373c4f7..7ff99922b0 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -129,6 +129,15 @@ func relayHelper(c *gin.Context) error { } else { quota = textResponse.Usage.TotalTokens } + ratio := common.RatioGPT3dot5 + if strings.HasPrefix(textRequest.Model, "gpt-4-32k") { + ratio = common.RatioGPT4_32k + } else if strings.HasPrefix(textRequest.Model, "gpt-4") { + ratio = common.RatioGPT4 + } else { + ratio = common.RatioGPT3dot5 + } + quota = int(float64(quota) * ratio) err := model.ConsumeTokenQuota(tokenId, quota) if err != nil { common.SysError("Error consuming token remain quota: " + err.Error()) diff --git a/model/option.go b/model/option.go index 47ed42f96a..bf7744a472 100644 --- a/model/option.go +++ b/model/option.go @@ -47,7 +47,9 @@ 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["RatioGPT3dot5"] = strconv.FormatFloat(common.RatioGPT3dot5, 'f', -1, 64) + common.OptionMap["RatioGPT4"] = strconv.FormatFloat(common.RatioGPT4, 'f', -1, 64) + common.OptionMap["RatioGPT4_32k"] = strconv.FormatFloat(common.RatioGPT4_32k, 'f', -1, 64) common.OptionMap["TopUpLink"] = common.TopUpLink common.OptionMapRWMutex.Unlock() options, _ := AllOption() @@ -136,8 +138,12 @@ 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 "RatioGPT3dot5": + common.RatioGPT3dot5, _ = strconv.ParseFloat(value, 64) + case "RatioGPT4": + common.RatioGPT4, _ = strconv.ParseFloat(value, 64) + case "RatioGPT4_32k": + common.RatioGPT4_32k, _ = strconv.ParseFloat(value, 64) case "TopUpLink": common.TopUpLink = value } diff --git a/web/src/components/SystemSetting.js b/web/src/components/SystemSetting.js index f05c8a4ad7..a7db156b1c 100644 --- a/web/src/components/SystemSetting.js +++ b/web/src/components/SystemSetting.js @@ -25,7 +25,9 @@ const SystemSetting = () => { TurnstileSecretKey: '', RegisterEnabled: '', QuotaForNewUser: 0, - BytesNumber2Quota: 0.8, + RatioGPT3dot5: 2, + RatioGPT4: 30, + RatioGPT4_32k: 60, TopUpLink: '' }); let originInputs = {}; @@ -91,7 +93,7 @@ const SystemSetting = () => { name === 'TurnstileSiteKey' || name === 'TurnstileSecretKey' || name === 'QuotaForNewUser' || - name === 'BytesNumber2Quota' || + name.startsWith('Ratio') || name === 'TopUpLink' ) { setInputs((inputs) => ({ ...inputs, [name]: value })); @@ -109,8 +111,14 @@ const SystemSetting = () => { if (originInputs['QuotaForNewUser'] !== inputs.QuotaForNewUser) { await updateOption('QuotaForNewUser', inputs.QuotaForNewUser); } - if (originInputs['BytesNumber2Quota'] !== inputs.BytesNumber2Quota) { - await updateOption('BytesNumber2Quota', inputs.BytesNumber2Quota); + if (originInputs['RatioGPT3dot5'] !== inputs.RatioGPT3dot5) { + await updateOption('RatioGPT3dot5', inputs.RatioGPT3dot5); + } + if (originInputs['RatioGPT4'] !== inputs.RatioGPT4) { + await updateOption('RatioGPT4', inputs.RatioGPT4); + } + if (originInputs['RatioGPT4_32k'] !== inputs.RatioGPT4_32k) { + await updateOption('RatioGPT4_32k', inputs.RatioGPT4_32k); } if (originInputs['TopUpLink'] !== inputs.TopUpLink) { await updateOption('TopUpLink', inputs.TopUpLink); @@ -261,24 +269,48 @@ const SystemSetting = () => { placeholder='例如:100' /> + + + + 保存运营设置