feat: support configuring ratio when estimating token number in stream mode
This commit is contained in:
parent
23ec541ba6
commit
480e789cd8
@ -48,6 +48,7 @@ var TurnstileSiteKey = ""
|
||||
var TurnstileSecretKey = ""
|
||||
|
||||
var QuotaForNewUser = 100
|
||||
var BytesNumber2Quota = 0.8
|
||||
|
||||
const (
|
||||
RoleGuestUser = 0
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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'
|
||||
/>
|
||||
<Form.Input
|
||||
label='Stream 模式下估算 token 时所使用的倍率'
|
||||
name='BytesNumber2Quota'
|
||||
onChange={handleInputChange}
|
||||
autoComplete='off'
|
||||
value={inputs.BytesNumber2Quota}
|
||||
type='number'
|
||||
step='0.01'
|
||||
min='0'
|
||||
placeholder='例如:0.8'
|
||||
/>
|
||||
<Form.Input
|
||||
label='充值链接'
|
||||
name='TopUpLink'
|
||||
|
Loading…
Reference in New Issue
Block a user