feat: able to set completion ration now (close #968)
This commit is contained in:
parent
26e2e646cb
commit
ea407f0054
@ -46,7 +46,7 @@ var ModelRatio = map[string]float64{
|
|||||||
"gpt-4-32k-0613": 30,
|
"gpt-4-32k-0613": 30,
|
||||||
"gpt-4-1106-preview": 5, // $0.01 / 1K tokens
|
"gpt-4-1106-preview": 5, // $0.01 / 1K tokens
|
||||||
"gpt-4-0125-preview": 5, // $0.01 / 1K tokens
|
"gpt-4-0125-preview": 5, // $0.01 / 1K tokens
|
||||||
"gpt-4-turbo-preview": 5, // $0.01 / 1K tokens
|
"gpt-4-turbo-preview": 5, // $0.01 / 1K tokens
|
||||||
"gpt-4-vision-preview": 5, // $0.01 / 1K tokens
|
"gpt-4-vision-preview": 5, // $0.01 / 1K tokens
|
||||||
"gpt-3.5-turbo": 0.75, // $0.0015 / 1K tokens
|
"gpt-3.5-turbo": 0.75, // $0.0015 / 1K tokens
|
||||||
"gpt-3.5-turbo-0301": 0.75,
|
"gpt-3.5-turbo-0301": 0.75,
|
||||||
@ -55,7 +55,7 @@ var ModelRatio = map[string]float64{
|
|||||||
"gpt-3.5-turbo-16k-0613": 1.5,
|
"gpt-3.5-turbo-16k-0613": 1.5,
|
||||||
"gpt-3.5-turbo-instruct": 0.75, // $0.0015 / 1K tokens
|
"gpt-3.5-turbo-instruct": 0.75, // $0.0015 / 1K tokens
|
||||||
"gpt-3.5-turbo-1106": 0.5, // $0.001 / 1K tokens
|
"gpt-3.5-turbo-1106": 0.5, // $0.001 / 1K tokens
|
||||||
"gpt-3.5-turbo-0125": 0.25, // $0.0005 / 1K tokens
|
"gpt-3.5-turbo-0125": 0.25, // $0.0005 / 1K tokens
|
||||||
"davinci-002": 1, // $0.002 / 1K tokens
|
"davinci-002": 1, // $0.002 / 1K tokens
|
||||||
"babbage-002": 0.2, // $0.0004 / 1K tokens
|
"babbage-002": 0.2, // $0.0004 / 1K tokens
|
||||||
"text-ada-001": 0.2,
|
"text-ada-001": 0.2,
|
||||||
@ -135,7 +135,25 @@ func GetModelRatio(name string) float64 {
|
|||||||
return ratio
|
return ratio
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var CompletionRatio = map[string]float64{}
|
||||||
|
|
||||||
|
func CompletionRatio2JSONString() string {
|
||||||
|
jsonBytes, err := json.Marshal(CompletionRatio)
|
||||||
|
if err != nil {
|
||||||
|
logger.SysError("error marshalling completion ratio: " + err.Error())
|
||||||
|
}
|
||||||
|
return string(jsonBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateCompletionRatioByJSONString(jsonStr string) error {
|
||||||
|
CompletionRatio = make(map[string]float64)
|
||||||
|
return json.Unmarshal([]byte(jsonStr), &CompletionRatio)
|
||||||
|
}
|
||||||
|
|
||||||
func GetCompletionRatio(name string) float64 {
|
func GetCompletionRatio(name string) float64 {
|
||||||
|
if ratio, ok := CompletionRatio[name]; ok {
|
||||||
|
return ratio
|
||||||
|
}
|
||||||
if strings.HasPrefix(name, "gpt-3.5") {
|
if strings.HasPrefix(name, "gpt-3.5") {
|
||||||
if strings.HasSuffix(name, "0125") {
|
if strings.HasSuffix(name, "0125") {
|
||||||
// https://openai.com/blog/new-embedding-models-and-api-updates
|
// https://openai.com/blog/new-embedding-models-and-api-updates
|
||||||
|
@ -66,6 +66,7 @@ func InitOptionMap() {
|
|||||||
config.OptionMap["PreConsumedQuota"] = strconv.Itoa(config.PreConsumedQuota)
|
config.OptionMap["PreConsumedQuota"] = strconv.Itoa(config.PreConsumedQuota)
|
||||||
config.OptionMap["ModelRatio"] = common.ModelRatio2JSONString()
|
config.OptionMap["ModelRatio"] = common.ModelRatio2JSONString()
|
||||||
config.OptionMap["GroupRatio"] = common.GroupRatio2JSONString()
|
config.OptionMap["GroupRatio"] = common.GroupRatio2JSONString()
|
||||||
|
config.OptionMap["CompletionRatio"] = common.CompletionRatio2JSONString()
|
||||||
config.OptionMap["TopUpLink"] = config.TopUpLink
|
config.OptionMap["TopUpLink"] = config.TopUpLink
|
||||||
config.OptionMap["ChatLink"] = config.ChatLink
|
config.OptionMap["ChatLink"] = config.ChatLink
|
||||||
config.OptionMap["QuotaPerUnit"] = strconv.FormatFloat(config.QuotaPerUnit, 'f', -1, 64)
|
config.OptionMap["QuotaPerUnit"] = strconv.FormatFloat(config.QuotaPerUnit, 'f', -1, 64)
|
||||||
@ -198,6 +199,8 @@ func updateOptionMap(key string, value string) (err error) {
|
|||||||
err = common.UpdateModelRatioByJSONString(value)
|
err = common.UpdateModelRatioByJSONString(value)
|
||||||
case "GroupRatio":
|
case "GroupRatio":
|
||||||
err = common.UpdateGroupRatioByJSONString(value)
|
err = common.UpdateGroupRatioByJSONString(value)
|
||||||
|
case "CompletionRatio":
|
||||||
|
err = common.UpdateCompletionRatioByJSONString(value)
|
||||||
case "TopUpLink":
|
case "TopUpLink":
|
||||||
config.TopUpLink = value
|
config.TopUpLink = value
|
||||||
case "ChatLink":
|
case "ChatLink":
|
||||||
|
@ -27,6 +27,7 @@ const OperationSetting = () => {
|
|||||||
QuotaRemindThreshold: 0,
|
QuotaRemindThreshold: 0,
|
||||||
PreConsumedQuota: 0,
|
PreConsumedQuota: 0,
|
||||||
ModelRatio: "",
|
ModelRatio: "",
|
||||||
|
CompletionRatio: "",
|
||||||
GroupRatio: "",
|
GroupRatio: "",
|
||||||
TopUpLink: "",
|
TopUpLink: "",
|
||||||
ChatLink: "",
|
ChatLink: "",
|
||||||
@ -52,9 +53,12 @@ const OperationSetting = () => {
|
|||||||
if (success) {
|
if (success) {
|
||||||
let newInputs = {};
|
let newInputs = {};
|
||||||
data.forEach((item) => {
|
data.forEach((item) => {
|
||||||
if (item.key === "ModelRatio" || item.key === "GroupRatio") {
|
if (item.key === "ModelRatio" || item.key === "GroupRatio" || item.key === "CompletionRatio") {
|
||||||
item.value = JSON.stringify(JSON.parse(item.value), null, 2);
|
item.value = JSON.stringify(JSON.parse(item.value), null, 2);
|
||||||
}
|
}
|
||||||
|
if (item.value === '{}') {
|
||||||
|
item.value = '';
|
||||||
|
}
|
||||||
newInputs[item.key] = item.value;
|
newInputs[item.key] = item.value;
|
||||||
});
|
});
|
||||||
setInputs(newInputs);
|
setInputs(newInputs);
|
||||||
@ -133,6 +137,13 @@ const OperationSetting = () => {
|
|||||||
}
|
}
|
||||||
await updateOption("GroupRatio", inputs.GroupRatio);
|
await updateOption("GroupRatio", inputs.GroupRatio);
|
||||||
}
|
}
|
||||||
|
if (originInputs['CompletionRatio'] !== inputs.CompletionRatio) {
|
||||||
|
if (!verifyJSON(inputs.CompletionRatio)) {
|
||||||
|
showError('补全倍率不是合法的 JSON 字符串');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await updateOption('CompletionRatio', inputs.CompletionRatio);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "quota":
|
case "quota":
|
||||||
if (originInputs["QuotaForNewUser"] !== inputs.QuotaForNewUser) {
|
if (originInputs["QuotaForNewUser"] !== inputs.QuotaForNewUser) {
|
||||||
@ -500,7 +511,20 @@ const OperationSetting = () => {
|
|||||||
placeholder="为一个 JSON 文本,键为模型名称,值为倍率"
|
placeholder="为一个 JSON 文本,键为模型名称,值为倍率"
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
<FormControl fullWidth>
|
||||||
|
<TextField
|
||||||
|
multiline
|
||||||
|
maxRows={15}
|
||||||
|
id="channel-CompletionRatio-label"
|
||||||
|
label="补全倍率"
|
||||||
|
value={inputs.CompletionRatio}
|
||||||
|
name="CompletionRatio"
|
||||||
|
onChange={handleInputChange}
|
||||||
|
aria-describedby="helper-text-channel-CompletionRatio-label"
|
||||||
|
minRows={5}
|
||||||
|
placeholder="为一个 JSON 文本,键为模型名称,值为倍率,此处的倍率设置是模型补全倍率相较于提示倍率的比例,使用该设置可强制覆盖 One API 的内部比例"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
<FormControl fullWidth>
|
<FormControl fullWidth>
|
||||||
<TextField
|
<TextField
|
||||||
multiline
|
multiline
|
||||||
|
@ -11,6 +11,7 @@ const OperationSetting = () => {
|
|||||||
QuotaRemindThreshold: 0,
|
QuotaRemindThreshold: 0,
|
||||||
PreConsumedQuota: 0,
|
PreConsumedQuota: 0,
|
||||||
ModelRatio: '',
|
ModelRatio: '',
|
||||||
|
CompletionRatio: '',
|
||||||
GroupRatio: '',
|
GroupRatio: '',
|
||||||
TopUpLink: '',
|
TopUpLink: '',
|
||||||
ChatLink: '',
|
ChatLink: '',
|
||||||
@ -34,9 +35,12 @@ const OperationSetting = () => {
|
|||||||
if (success) {
|
if (success) {
|
||||||
let newInputs = {};
|
let newInputs = {};
|
||||||
data.forEach((item) => {
|
data.forEach((item) => {
|
||||||
if (item.key === 'ModelRatio' || item.key === 'GroupRatio') {
|
if (item.key === 'ModelRatio' || item.key === 'GroupRatio' || item.key === 'CompletionRatio') {
|
||||||
item.value = JSON.stringify(JSON.parse(item.value), null, 2);
|
item.value = JSON.stringify(JSON.parse(item.value), null, 2);
|
||||||
}
|
}
|
||||||
|
if (item.value === '{}') {
|
||||||
|
item.value = '';
|
||||||
|
}
|
||||||
newInputs[item.key] = item.value;
|
newInputs[item.key] = item.value;
|
||||||
});
|
});
|
||||||
setInputs(newInputs);
|
setInputs(newInputs);
|
||||||
@ -101,6 +105,13 @@ const OperationSetting = () => {
|
|||||||
}
|
}
|
||||||
await updateOption('GroupRatio', inputs.GroupRatio);
|
await updateOption('GroupRatio', inputs.GroupRatio);
|
||||||
}
|
}
|
||||||
|
if (originInputs['CompletionRatio'] !== inputs.CompletionRatio) {
|
||||||
|
if (!verifyJSON(inputs.CompletionRatio)) {
|
||||||
|
showError('补全倍率不是合法的 JSON 字符串');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await updateOption('CompletionRatio', inputs.CompletionRatio);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'quota':
|
case 'quota':
|
||||||
if (originInputs['QuotaForNewUser'] !== inputs.QuotaForNewUser) {
|
if (originInputs['QuotaForNewUser'] !== inputs.QuotaForNewUser) {
|
||||||
@ -271,10 +282,10 @@ const OperationSetting = () => {
|
|||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
/>
|
/>
|
||||||
<Form.Checkbox
|
<Form.Checkbox
|
||||||
checked={inputs.AutomaticEnableChannelEnabled === 'true'}
|
checked={inputs.AutomaticEnableChannelEnabled === 'true'}
|
||||||
label='成功时自动启用通道'
|
label='成功时自动启用通道'
|
||||||
name='AutomaticEnableChannelEnabled'
|
name='AutomaticEnableChannelEnabled'
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
/>
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Form.Button onClick={() => {
|
<Form.Button onClick={() => {
|
||||||
@ -344,6 +355,17 @@ const OperationSetting = () => {
|
|||||||
placeholder='为一个 JSON 文本,键为模型名称,值为倍率'
|
placeholder='为一个 JSON 文本,键为模型名称,值为倍率'
|
||||||
/>
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
|
<Form.Group widths='equal'>
|
||||||
|
<Form.TextArea
|
||||||
|
label='补全倍率'
|
||||||
|
name='CompletionRatio'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
style={{ minHeight: 250, fontFamily: 'JetBrains Mono, Consolas' }}
|
||||||
|
autoComplete='new-password'
|
||||||
|
value={inputs.CompletionRatio}
|
||||||
|
placeholder='为一个 JSON 文本,键为模型名称,值为倍率,此处的倍率设置是模型补全倍率相较于提示倍率的比例,使用该设置可强制覆盖 One API 的内部比例'
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
<Form.Group widths='equal'>
|
<Form.Group widths='equal'>
|
||||||
<Form.TextArea
|
<Form.TextArea
|
||||||
label='分组倍率'
|
label='分组倍率'
|
||||||
|
Loading…
Reference in New Issue
Block a user