feat: able to configure ratio for different models (close #26)
This commit is contained in:
parent
b08cd7e104
commit
d93cb8f645
@ -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
|
||||
|
@ -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())
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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);
|
||||
@ -260,17 +268,6 @@ 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'
|
||||
@ -281,6 +278,41 @@ const SystemSetting = () => {
|
||||
placeholder='例如发卡网站的购买链接'
|
||||
/>
|
||||
</Form.Group>
|
||||
<Form.Group widths={3}>
|
||||
<Form.Input
|
||||
label='GPT-3.5 系列模型倍率'
|
||||
name='RatioGPT3dot5'
|
||||
onChange={handleInputChange}
|
||||
autoComplete='off'
|
||||
value={inputs.RatioGPT3dot5}
|
||||
type='number'
|
||||
step='0.01'
|
||||
min='0'
|
||||
placeholder='例如:2'
|
||||
/>
|
||||
<Form.Input
|
||||
label='GPT-4 系列模型倍率'
|
||||
name='RatioGPT4'
|
||||
onChange={handleInputChange}
|
||||
autoComplete='off'
|
||||
value={inputs.RatioGPT4}
|
||||
type='number'
|
||||
step='0.01'
|
||||
min='0'
|
||||
placeholder='例如:30'
|
||||
/>
|
||||
<Form.Input
|
||||
label='GPT-4 32k 系列模型倍率'
|
||||
name='RatioGPT4_32k'
|
||||
onChange={handleInputChange}
|
||||
autoComplete='off'
|
||||
value={inputs.RatioGPT4_32k}
|
||||
type='number'
|
||||
step='0.01'
|
||||
min='0'
|
||||
placeholder='例如:60'
|
||||
/>
|
||||
</Form.Group>
|
||||
<Form.Button onClick={submitOperationConfig}>保存运营设置</Form.Button>
|
||||
<Divider />
|
||||
<Header as='h3'>
|
||||
|
Loading…
Reference in New Issue
Block a user