From 4196351e48ef142e570532dc14b0af86062e8036 Mon Sep 17 00:00:00 2001 From: jialin Date: Wed, 15 Oct 2025 11:22:41 +0800 Subject: [PATCH] fix: backend edit format --- src/components/seal-form/seal-textarea.tsx | 1 + src/locales/en-US/backends.ts | 2 +- src/locales/en-US/models.ts | 4 +- src/locales/ja-JP/backends.ts | 2 +- src/locales/ja-JP/models.ts | 7 ++- src/locales/ru-RU/backends.ts | 2 +- src/locales/ru-RU/models.ts | 7 ++- src/locales/zh-CN/backends.ts | 2 +- src/locales/zh-CN/models.ts | 4 +- src/pages/backends/components/add-modal.tsx | 31 ++++++---- .../components/version-info-modal.tsx | 6 +- src/pages/backends/config/index.ts | 6 +- src/pages/backends/config/schema/create.json | 60 +++++++++++++++++-- .../config/schema/update-builtin.json | 14 ++--- .../backends/config/schema/update-custom.json | 14 ++--- src/pages/backends/config/types.ts | 4 +- src/pages/backends/forms/version-info.tsx | 9 +++ src/pages/backends/index.tsx | 28 +++++---- src/pages/llmodels/forms/backend.tsx | 3 + 19 files changed, 147 insertions(+), 59 deletions(-) diff --git a/src/components/seal-form/seal-textarea.tsx b/src/components/seal-form/seal-textarea.tsx index 536eabf0..44bcd3c6 100644 --- a/src/components/seal-form/seal-textarea.tsx +++ b/src/components/seal-form/seal-textarea.tsx @@ -127,6 +127,7 @@ const SealTextArea: React.FC = ( > = (props) => { const onOk = () => { if (activeKey === 'yaml') { const content = editorRef.current?.getContent(); - const valid = editorRef.current?.validate(); - if (valid) { - onSubmitYaml({ content: content }); - } + onSubmitYaml({ content: content }); } else { formRef.current?.submit(); } @@ -104,30 +101,40 @@ const AddModal: React.FC = (props) => { ); const builtInVersions = Object.keys( - values.build_in_version_configs || {} + values.built_in_version_configs || {} ).map((key) => ({ version_no: key, - image_name: values.build_in_version_configs?.[key]?.image_name, - run_command: values.build_in_version_configs?.[key]?.run_command, + image_name: values.built_in_version_configs?.[key]?.image_name, + run_command: values.built_in_version_configs?.[key]?.run_command, is_default: key === values.default_version, - build_in_frameworks: - values.build_in_version_configs?.[key]?.build_in_frameworks || [], + built_in_frameworks: + values.built_in_version_configs?.[key]?.built_in_frameworks || [], is_built_in: true })); return { ...values, version_configs: versionConfigs, - build_in_version_configs: builtInVersions + built_in_version_configs: builtInVersions }; }; // built-in backend does not allow to edit default_version const initYamlContent = (values: any) => { + const copyValues = structuredClone(values); + copyValues.version_configs = _.mapValues( + copyValues.version_configs || {}, + (v: any) => { + return _.omit(v, ['built_in_frameworks']); + } + ); + if (currentData?.is_built_in) { - return json2Yaml(_.pick(values, backendFields)); + return json2Yaml(_.pick(copyValues, backendFields)); } - return json2Yaml(_.pick(values, [...backendFields, 'default_version'])); + return json2Yaml( + _.pick(copyValues, [...backendFields, 'default_version']) + ); }; if (action === PageAction.EDIT && open) { diff --git a/src/pages/backends/components/version-info-modal.tsx b/src/pages/backends/components/version-info-modal.tsx index 2ace0475..5ee32937 100644 --- a/src/pages/backends/components/version-info-modal.tsx +++ b/src/pages/backends/components/version-info-modal.tsx @@ -20,8 +20,8 @@ const VersionInfoModal: React.FC = ({ useEffect(() => { if (open && currentData) { - // add is_built_in field to build_in_version_configs - const builtInVersions = currentData.build_in_version_configs || {}; + // add is_built_in field to built_in_version_configs + const builtInVersions = currentData.built_in_version_configs || {}; for (const key in builtInVersions) { if (builtInVersions?.hasOwnProperty(key)) { @@ -41,7 +41,7 @@ const VersionInfoModal: React.FC = ({ run_command: value.run_command, is_default: key === currentData.default_version, availableFrameworks: [ - ...(value.build_in_frameworks || []), + ...(value.built_in_frameworks || []), ...(value.custom_framework ? [value.custom_framework] : []) ], is_built_in: value.is_built_in || false diff --git a/src/pages/backends/config/index.ts b/src/pages/backends/config/index.ts index a6274a01..771ff631 100644 --- a/src/pages/backends/config/index.ts +++ b/src/pages/backends/config/index.ts @@ -114,7 +114,7 @@ export const backendFields = [ 'health_check_path', 'default_run_command', 'version_configs', - 'default_backend_parameters' + 'default_backend_param' ]; export const frameworks = [ { @@ -148,6 +148,8 @@ backend_name: SGLang description: SGLang backend default_version: v0.5.1 health_check_path: /health +default_backend_param: + - --host default_run_command: run sglang version_configs: v0.0.1: @@ -158,6 +160,4 @@ version_configs: image_name: lm/sglang run_command: custom_framework: -default_backend_parameters: - - --host `; diff --git a/src/pages/backends/config/schema/create.json b/src/pages/backends/config/schema/create.json index 16a87012..a44ee562 100644 --- a/src/pages/backends/config/schema/create.json +++ b/src/pages/backends/config/schema/create.json @@ -14,6 +14,17 @@ "type": "string", "description": "default backend version" }, + "is_built_in": { + "type": "boolean", + "description": "is built-in backend" + }, + "default_backend_param": { + "type": "array", + "items": { + "type": "string" + }, + "description": "default backend parameter" + }, "default_run_command": { "type": ["string", "null"], "description": "default start command" @@ -48,12 +59,51 @@ "additionalProperties": false, "description": "multiple backend versions" }, - "default_backend_parameters": { - "type": "array", - "items": { - "type": "string" + "built_in_version_configs": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9._-]+$": { + "type": "object", + "properties": { + "image_name": { + "type": "string", + "description": "image name" + }, + "run_command": { + "type": ["string", "null"], + "description": "start command" + }, + "custom_framework": { + "type": ["string", "null"], + "description": "custom framework" + }, + "built_in_frameworks": { + "type": "array", + "items": { + "type": "string" + }, + "description": "built-in frameworks" + } + }, + "required": ["image_name", "run_command"], + "additionalProperties": false + } }, - "description": "default backend parameters" + "additionalProperties": false, + "description": "multiple backend versions" + }, + "framework_index_map": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9._-]+$": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": false, + "description": "framework to version mapping" } }, "required": ["backend_name", "default_version", "version_configs"], diff --git a/src/pages/backends/config/schema/update-builtin.json b/src/pages/backends/config/schema/update-builtin.json index dfebffdb..6c5773bc 100644 --- a/src/pages/backends/config/schema/update-builtin.json +++ b/src/pages/backends/config/schema/update-builtin.json @@ -5,6 +5,13 @@ "type": ["string", "null"], "description": "backend description" }, + "default_backend_param": { + "type": "array", + "items": { + "type": "string" + }, + "description": "default backend parameter" + }, "default_run_command": { "type": ["string", "null"], "description": "default start command" @@ -38,13 +45,6 @@ }, "additionalProperties": false, "description": "multiple backend versions" - }, - "default_backend_parameters": { - "type": "array", - "items": { - "type": "string" - }, - "description": "default backend parameters" } }, "required": ["version_configs"], diff --git a/src/pages/backends/config/schema/update-custom.json b/src/pages/backends/config/schema/update-custom.json index 5a3d86c1..528d3d39 100644 --- a/src/pages/backends/config/schema/update-custom.json +++ b/src/pages/backends/config/schema/update-custom.json @@ -9,6 +9,13 @@ "type": "string", "description": "default backend version" }, + "default_backend_param": { + "type": "array", + "items": { + "type": "string" + }, + "description": "default backend parameter" + }, "default_run_command": { "type": ["string", "null"], "description": "default start command" @@ -42,13 +49,6 @@ }, "additionalProperties": false, "description": "multiple backend versions" - }, - "default_backend_parameters": { - "type": "array", - "items": { - "type": "string" - }, - "description": "default backend parameters" } }, "required": ["default_version", "version_configs"], diff --git a/src/pages/backends/config/types.ts b/src/pages/backends/config/types.ts index 0f909290..14e5b175 100644 --- a/src/pages/backends/config/types.ts +++ b/src/pages/backends/config/types.ts @@ -2,7 +2,7 @@ export interface VersionConfigs { image_name: string; run_command: string; is_default: boolean; - build_in_frameworks?: string[]; + built_in_frameworks?: string[]; custom_framework?: string; version_no?: string; is_built_in?: boolean; @@ -29,6 +29,6 @@ export interface ListItem extends FormData { is_built_in?: boolean; created_at?: string; updated_at?: string; - build_in_version_configs?: Record; + built_in_version_configs?: Record; framework_index_map?: Record; } diff --git a/src/pages/backends/forms/version-info.tsx b/src/pages/backends/forms/version-info.tsx index ddc375eb..a2757027 100644 --- a/src/pages/backends/forms/version-info.tsx +++ b/src/pages/backends/forms/version-info.tsx @@ -90,6 +90,15 @@ export const VersionItem: React.FC = ({ data }) => { {intl.formatMessage({ id: 'backend.builtin' })} )} + {!data.is_built_in && data.is_default && ( + + {intl.formatMessage({ id: 'backend.isDefault' })} + + )} {data.image_name && ( diff --git a/src/pages/backends/index.tsx b/src/pages/backends/index.tsx index 8d3b6ff9..dc5ae9ec 100644 --- a/src/pages/backends/index.tsx +++ b/src/pages/backends/index.tsx @@ -62,7 +62,7 @@ const BackendList = () => { currentData?: Partial; }>({ open: false }); - // build_in_version_configs is read-only, but needs to be included when updating + // built_in_version_configs is read-only, but needs to be included when updating const handleOnSubmit = async (values: FormData) => { try { if (openModalStatus.action === 'create') { @@ -70,9 +70,10 @@ const BackendList = () => { } else { await updateBackend(openModalStatus.currentData!.id!, { data: { - build_in_version_configs: - openModalStatus.currentData?.build_in_version_configs, - ..._.omit(values, ['build_in_version_configs']) + built_in_version_configs: + openModalStatus.currentData?.built_in_version_configs, + ..._.omit(values, ['built_in_version_configs']), + health_check_path: values.health_check_path || null } }); } @@ -85,7 +86,7 @@ const BackendList = () => { } catch (error) {} }; - // build_in_version_configs needs to be included when updating from YAML, but not allowed to be changed + // built_in_version_configs needs to be included when updating from YAML, but not allowed to be changed const handleOnSubmitYaml = async (values: { content: string }) => { try { if (openModalStatus.action === 'create') { @@ -95,8 +96,8 @@ const BackendList = () => { const yamlContent = json2Yaml({ backend_name: openModalStatus.currentData?.backend_name, default_version: openModalStatus.currentData?.default_version, - build_in_version_configs: - openModalStatus.currentData?.build_in_version_configs, + built_in_version_configs: + openModalStatus.currentData?.built_in_version_configs, ...jsonData }); await updateBackendFromYAML(openModalStatus.currentData!.id!, { @@ -122,7 +123,6 @@ const BackendList = () => { }; const handleOnSelect = (item: any) => { - console.log('selected item:', item); if (item.action === 'edit') { setOpenModalStatus({ open: true, @@ -134,8 +134,16 @@ const BackendList = () => { name: item.data.backend_name }); } else if (item.action === 'export') { - // Export YAML action - exportYAML(item.data); + const currentData = structuredClone(item.data); + + currentData.version_configs = _.mapValues( + currentData.version_configs, + (v: any) => { + return _.omit(v, ['built_in_frameworks']); + } + ); + + exportYAML(_.omit(currentData, ['id', 'created_at', 'updated_at'])); } else if (item.action === 'view_versions') { setOpenVersionInfoModal({ open: true, diff --git a/src/pages/llmodels/forms/backend.tsx b/src/pages/llmodels/forms/backend.tsx index 8b27a0dc..07b88cd2 100644 --- a/src/pages/llmodels/forms/backend.tsx +++ b/src/pages/llmodels/forms/backend.tsx @@ -143,6 +143,9 @@ const BackendFields: React.FC = () => { scaleSize={true} allowClear label={intl.formatMessage({ id: 'backend.runCommand' })} + placeholder={intl.formatMessage({ + id: 'models.form.runCommandPlaceholder' + })} >