mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-07 01:56:53 +00:00
feat(default): reorganize system settings pricing UI
Refine the default system settings structure and model pricing editor so pricing configuration is easier to scan and edit.
This commit is contained in:
@@ -179,17 +179,24 @@ const groupSchema = z.object({
|
||||
|
||||
type ModelFormValues = z.infer<typeof modelSchema>
|
||||
type GroupFormValues = z.infer<typeof groupSchema>
|
||||
type RatioTabId = 'models' | 'groups' | 'tool-prices' | 'upstream-sync'
|
||||
|
||||
type RatioSettingsCardProps = {
|
||||
modelDefaults: ModelFormValues
|
||||
groupDefaults: GroupFormValues
|
||||
toolPricesDefault: string
|
||||
titleKey?: string
|
||||
descriptionKey?: string
|
||||
visibleTabs?: RatioTabId[]
|
||||
}
|
||||
|
||||
export function RatioSettingsCard({
|
||||
modelDefaults,
|
||||
groupDefaults,
|
||||
toolPricesDefault,
|
||||
titleKey = 'Pricing Ratios',
|
||||
descriptionKey = 'Configure model, caching, and group ratios used for billing',
|
||||
visibleTabs = ['models', 'groups', 'tool-prices', 'upstream-sync'],
|
||||
}: RatioSettingsCardProps) {
|
||||
const { t } = useTranslation()
|
||||
const updateOption = useUpdateOption()
|
||||
@@ -414,61 +421,79 @@ export function RatioSettingsCard({
|
||||
resetMutate()
|
||||
}, [resetMutate])
|
||||
|
||||
const tabLabels: Record<RatioTabId, string> = {
|
||||
models: 'Model ratios',
|
||||
groups: 'Group ratios',
|
||||
'tool-prices': 'Tool prices',
|
||||
'upstream-sync': 'Upstream price sync',
|
||||
}
|
||||
const tabsGridClass =
|
||||
{
|
||||
1: 'grid-cols-1',
|
||||
2: 'grid-cols-2',
|
||||
3: 'grid-cols-3',
|
||||
4: 'grid-cols-4',
|
||||
}[visibleTabs.length] ?? 'grid-cols-4'
|
||||
const defaultTab = visibleTabs[0] ?? 'models'
|
||||
|
||||
const renderTabContent = (tab: RatioTabId) => {
|
||||
if (tab === 'models') {
|
||||
return (
|
||||
<ModelRatioForm
|
||||
form={modelForm}
|
||||
onSave={saveModelRatios}
|
||||
onReset={handleResetRatios}
|
||||
isSaving={updateOption.isPending}
|
||||
isResetting={resetMutation.isPending}
|
||||
/>
|
||||
)
|
||||
}
|
||||
if (tab === 'groups') {
|
||||
return (
|
||||
<GroupRatioForm
|
||||
form={groupForm}
|
||||
onSave={saveGroupRatios}
|
||||
isSaving={updateOption.isPending}
|
||||
/>
|
||||
)
|
||||
}
|
||||
if (tab === 'tool-prices') {
|
||||
return <ToolPriceSettings defaultValue={toolPricesDefault} />
|
||||
}
|
||||
return (
|
||||
<UpstreamRatioSync
|
||||
modelRatios={{
|
||||
ModelPrice: modelDefaults.ModelPrice,
|
||||
ModelRatio: modelDefaults.ModelRatio,
|
||||
CompletionRatio: modelDefaults.CompletionRatio,
|
||||
CacheRatio: modelDefaults.CacheRatio,
|
||||
CreateCacheRatio: modelDefaults.CreateCacheRatio,
|
||||
ImageRatio: modelDefaults.ImageRatio,
|
||||
AudioRatio: modelDefaults.AudioRatio,
|
||||
AudioCompletionRatio: modelDefaults.AudioCompletionRatio,
|
||||
'billing_setting.billing_mode': modelDefaults.BillingMode,
|
||||
'billing_setting.billing_expr': modelDefaults.BillingExpr,
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<SettingsSection
|
||||
title={t('Pricing Ratios')}
|
||||
description={t(
|
||||
'Configure model, caching, and group ratios used for billing'
|
||||
)}
|
||||
>
|
||||
<Tabs defaultValue='models' className='space-y-6'>
|
||||
<TabsList className='grid w-full grid-cols-4'>
|
||||
<TabsTrigger value='models'>{t('Model ratios')}</TabsTrigger>
|
||||
<TabsTrigger value='groups'>{t('Group ratios')}</TabsTrigger>
|
||||
<TabsTrigger value='tool-prices'>{t('Tool prices')}</TabsTrigger>
|
||||
<TabsTrigger value='upstream-sync'>
|
||||
{t('Upstream price sync')}
|
||||
</TabsTrigger>
|
||||
<SettingsSection title={t(titleKey)} description={t(descriptionKey)}>
|
||||
<Tabs defaultValue={defaultTab} className='space-y-6'>
|
||||
<TabsList className={`grid w-full ${tabsGridClass}`}>
|
||||
{visibleTabs.map((tab) => (
|
||||
<TabsTrigger key={tab} value={tab}>
|
||||
{t(tabLabels[tab])}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value='models'>
|
||||
<ModelRatioForm
|
||||
form={modelForm}
|
||||
onSave={saveModelRatios}
|
||||
onReset={handleResetRatios}
|
||||
isSaving={updateOption.isPending}
|
||||
isResetting={resetMutation.isPending}
|
||||
/>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value='groups'>
|
||||
<GroupRatioForm
|
||||
form={groupForm}
|
||||
onSave={saveGroupRatios}
|
||||
isSaving={updateOption.isPending}
|
||||
/>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value='tool-prices'>
|
||||
<ToolPriceSettings defaultValue={toolPricesDefault} />
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value='upstream-sync'>
|
||||
<UpstreamRatioSync
|
||||
modelRatios={{
|
||||
ModelPrice: modelDefaults.ModelPrice,
|
||||
ModelRatio: modelDefaults.ModelRatio,
|
||||
CompletionRatio: modelDefaults.CompletionRatio,
|
||||
CacheRatio: modelDefaults.CacheRatio,
|
||||
CreateCacheRatio: modelDefaults.CreateCacheRatio,
|
||||
ImageRatio: modelDefaults.ImageRatio,
|
||||
AudioRatio: modelDefaults.AudioRatio,
|
||||
AudioCompletionRatio: modelDefaults.AudioCompletionRatio,
|
||||
'billing_setting.billing_mode': modelDefaults.BillingMode,
|
||||
'billing_setting.billing_expr': modelDefaults.BillingExpr,
|
||||
}}
|
||||
/>
|
||||
</TabsContent>
|
||||
{visibleTabs.map((tab) => (
|
||||
<TabsContent key={tab} value={tab}>
|
||||
{renderTabContent(tab)}
|
||||
</TabsContent>
|
||||
))}
|
||||
</Tabs>
|
||||
|
||||
<ConfirmDialog
|
||||
|
||||
Reference in New Issue
Block a user