Commit f424f906 by Seefs Committed by GitHub

feat: sync upstream pricing from pricing endpoint (#4452)

* feat: sync upstream pricing from pricing endpoint

* feat: sync upstream pricing with expression priority

* fix: add feedback while syncing upstream pricing

* fix: show loading state for empty upstream pricing sync
parent cc4ad6c3
...@@ -5,11 +5,14 @@ import ( ...@@ -5,11 +5,14 @@ import (
"github.com/QuantumNous/new-api/pkg/billingexpr" "github.com/QuantumNous/new-api/pkg/billingexpr"
"github.com/QuantumNous/new-api/setting/config" "github.com/QuantumNous/new-api/setting/config"
"github.com/samber/lo"
) )
const ( const (
BillingModeRatio = "ratio" BillingModeRatio = "ratio"
BillingModeTieredExpr = "tiered_expr" BillingModeTieredExpr = "tiered_expr"
BillingModeField = "billing_mode"
BillingExprField = "billing_expr"
) )
// BillingSetting is managed by config.GlobalConfig.Register. // BillingSetting is managed by config.GlobalConfig.Register.
...@@ -44,6 +47,25 @@ func GetBillingExpr(model string) (string, bool) { ...@@ -44,6 +47,25 @@ func GetBillingExpr(model string) (string, bool) {
return expr, ok return expr, ok
} }
func GetBillingModeCopy() map[string]string {
return lo.Assign(billingSetting.BillingMode)
}
func GetBillingExprCopy() map[string]string {
return lo.Assign(billingSetting.BillingExpr)
}
func GetPricingSyncData(base map[string]any) map[string]any {
extra := make(map[string]any, 2)
if modes := GetBillingModeCopy(); len(modes) > 0 {
extra[BillingModeField] = modes
}
if exprs := GetBillingExprCopy(); len(exprs) > 0 {
extra[BillingExprField] = exprs
}
return lo.Assign(base, extra)
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Smoke test (called externally for validation before save) // Smoke test (called externally for validation before save)
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
......
...@@ -709,6 +709,18 @@ func GetCompletionRatioCopy() map[string]float64 { ...@@ -709,6 +709,18 @@ func GetCompletionRatioCopy() map[string]float64 {
return completionRatioMap.ReadAll() return completionRatioMap.ReadAll()
} }
func GetImageRatioCopy() map[string]float64 {
return imageRatioMap.ReadAll()
}
func GetAudioRatioCopy() map[string]float64 {
return audioRatioMap.ReadAll()
}
func GetAudioCompletionRatioCopy() map[string]float64 {
return audioCompletionRatioMap.ReadAll()
}
// 转换模型名,减少渠道必须配置各种带参数模型 // 转换模型名,减少渠道必须配置各种带参数模型
func FormatMatchingModelName(name string) string { func FormatMatchingModelName(name string) string {
......
...@@ -155,8 +155,8 @@ const ChannelSelectorModal = forwardRef( ...@@ -155,8 +155,8 @@ const ChannelSelectorModal = forwardRef(
onChange={handleTypeChange} onChange={handleTypeChange}
style={{ width: 120 }} style={{ width: 120 }}
optionList={[ optionList={[
{ label: 'ratio_config', value: 'ratio_config' },
{ label: 'pricing', value: 'pricing' }, { label: 'pricing', value: 'pricing' },
{ label: 'ratio_config', value: 'ratio_config' },
{ label: 'OpenRouter', value: 'openrouter' }, { label: 'OpenRouter', value: 'openrouter' },
{ label: 'custom', value: 'custom' }, { label: 'custom', value: 'custom' },
]} ]}
......
...@@ -106,7 +106,7 @@ const RatioSetting = () => { ...@@ -106,7 +106,7 @@ const RatioSetting = () => {
<Tabs.TabPane tab={t('未设置价格模型')} itemKey='unset_models'> <Tabs.TabPane tab={t('未设置价格模型')} itemKey='unset_models'>
<ModelRatioNotSetEditor options={inputs} refresh={onRefresh} /> <ModelRatioNotSetEditor options={inputs} refresh={onRefresh} />
</Tabs.TabPane> </Tabs.TabPane>
<Tabs.TabPane tab={t('上游倍率同步')} itemKey='upstream_sync'> <Tabs.TabPane tab={t('上游价格同步')} itemKey='upstream_sync'>
<UpstreamRatioSync options={inputs} refresh={onRefresh} /> <UpstreamRatioSync options={inputs} refresh={onRefresh} />
</Tabs.TabPane> </Tabs.TabPane>
<Tabs.TabPane tab={t('工具调用定价')} itemKey='tool_price'> <Tabs.TabPane tab={t('工具调用定价')} itemKey='tool_price'>
......
...@@ -19,7 +19,7 @@ For commercial licensing, please contact support@quantumnous.com ...@@ -19,7 +19,7 @@ For commercial licensing, please contact support@quantumnous.com
export const ITEMS_PER_PAGE = 10; // this value must keep same as the one defined in backend! export const ITEMS_PER_PAGE = 10; // this value must keep same as the one defined in backend!
export const DEFAULT_ENDPOINT = '/api/ratio_config'; export const DEFAULT_ENDPOINT = '/api/pricing';
export const TABLE_COMPACT_MODES_KEY = 'table_compact_modes'; export const TABLE_COMPACT_MODES_KEY = 'table_compact_modes';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment