Просмотр исходного кода

fix: 支持带供应商前缀的模型名称倍率匹配

当模型名称包含供应商前缀(如 "openai/o3-mini")时,自动尝试去掉前缀重新查找倍率配置。

- 在 GetModelPrice 和 GetModelRatio 函数中添加前缀剥离逻辑
- 在前端倍率配置页面添加提示说明

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat/alipay-payment
fengsilin 1 месяц назад
Родитель
Сommit
96e71a3be4
2 измененных файлов: 23 добавлений и 0 удалений
  1. +22
    -0
      setting/ratio_setting/model_ratio.go
  2. +1
    -0
      web/src/pages/Setting/Ratio/ModelRatioSettings.jsx

+ 22
- 0
setting/ratio_setting/model_ratio.go Просмотреть файл

@@ -370,6 +370,17 @@ func GetModelPrice(name string, printErr bool) (float64, bool) {

price, ok := modelPriceMap.Get(name)
if !ok {
// 新增:如果模型名称包含 "/",尝试去掉供应商前缀后重新查找
// 例如: "openai/gpt-4o" -> "gpt-4o"
if strings.Contains(name, "/") {
parts := strings.SplitN(name, "/", 2)
if len(parts) == 2 {
baseName := FormatMatchingModelName(parts[1])
if basePrice, ok := modelPriceMap.Get(baseName); ok {
return basePrice, true
}
}
}
if printErr {
common.SysError("model price not found: " + name)
}
@@ -401,6 +412,17 @@ func GetModelRatio(name string) (float64, bool, string) {
}
//return 0, true, name
}
// 新增:如果模型名称包含 "/",尝试去掉供应商前缀后重新查找
// 例如: "openai/o3-mini" -> "o3-mini"
if strings.Contains(name, "/") {
parts := strings.SplitN(name, "/", 2)
if len(parts) == 2 {
baseName := FormatMatchingModelName(parts[1])
if baseRatio, ok := modelRatioMap.Get(baseName); ok {
return baseRatio, true, name
}
}
}
return 37.5, operation_setting.SelfUseModeEnabled, name
}
return ratio, true, name


+ 1
- 0
web/src/pages/Setting/Ratio/ModelRatioSettings.jsx Просмотреть файл

@@ -167,6 +167,7 @@ export default function ModelRatioSettings(props) {
<Col xs={24} sm={16}>
<Form.TextArea
label={t('模型倍率')}
extraText={t('支持带供应商前缀的模型名称(如 "openai/o3-mini"),系统会自动尝试去掉前缀匹配')}
placeholder={t('为一个 JSON 文本,键为模型名称,值为倍率')}
field={'ModelRatio'}
autosize={{ minRows: 6, maxRows: 12 }}


Загрузка…
Отмена
Сохранить