From 75c05bb4b8a55611b491f89dcda011f210c313d8 Mon Sep 17 00:00:00 2001 From: QuentinHsu Date: Sat, 6 Jun 2026 14:36:21 +0800 Subject: [PATCH] perf(model-pricing): improve JSON pricing editor layout - render pricing JSON fields from shared configuration to reduce duplicated form markup. - use fixed-height JSON textareas so long model maps scroll internally instead of stretching the page. - arrange JSON editors in responsive columns to make wider settings pages easier to scan. --- .../models/model-ratio-form.tsx | 251 +++++++----------- 1 file changed, 102 insertions(+), 149 deletions(-) diff --git a/web/default/src/features/system-settings/models/model-ratio-form.tsx b/web/default/src/features/system-settings/models/model-ratio-form.tsx index 38c3a530..6cfa93fa 100644 --- a/web/default/src/features/system-settings/models/model-ratio-form.tsx +++ b/web/default/src/features/system-settings/models/model-ratio-form.tsx @@ -65,6 +65,97 @@ type ModelRatioFormProps = { isResetting: boolean } +type ModelJsonFieldName = + | 'ModelPrice' + | 'ModelRatio' + | 'CacheRatio' + | 'CreateCacheRatio' + | 'CompletionRatio' + | 'ImageRatio' + | 'AudioRatio' + | 'AudioCompletionRatio' + +const modelJsonFields: Array<{ + name: ModelJsonFieldName + labelKey: string + descriptionKey: string +}> = [ + { + name: 'ModelPrice', + labelKey: 'Model fixed pricing', + descriptionKey: + 'JSON map of model → USD cost per request. Takes precedence over ratio based billing.', + }, + { + name: 'ModelRatio', + labelKey: 'Model ratio', + descriptionKey: 'JSON map of model → multiplier applied to quota billing.', + }, + { + name: 'CacheRatio', + labelKey: 'Prompt cache ratio', + descriptionKey: 'Optional ratio used when upstream cache hits occur.', + }, + { + name: 'CreateCacheRatio', + labelKey: 'Create cache ratio', + descriptionKey: + 'Ratio applied when creating cache entries for supported models.', + }, + { + name: 'CompletionRatio', + labelKey: 'Completion ratio', + descriptionKey: + 'Applies to custom completion endpoints. JSON map of model → ratio.', + }, + { + name: 'ImageRatio', + labelKey: 'Image ratio', + descriptionKey: 'Configure per-model ratio for image inputs or outputs.', + }, + { + name: 'AudioRatio', + labelKey: 'Audio ratio', + descriptionKey: + 'Ratio applied to audio inputs where supported by the upstream model.', + }, + { + name: 'AudioCompletionRatio', + labelKey: 'Audio completion ratio', + descriptionKey: 'Ratio applied to audio completions for streaming models.', + }, +] + +function ModelJsonTextareaField(props: { + form: UseFormReturn + name: ModelJsonFieldName + label: string + description: string +}) { + return ( + ( + + {props.label} + +