fix: backend option format

This commit is contained in:
jialin
2025-11-04 18:07:14 +08:00
parent 4ca6a221e4
commit 7e5edd6387
5 changed files with 38 additions and 38 deletions
+6 -1
View File
@@ -299,8 +299,13 @@ export interface BackendGroupOption {
}
export interface BackendOption {
value: string;
label: string;
options: BackendGroupOption[];
title?: string;
default_backend_param: string[];
default_version: string;
isBuiltIn: boolean;
versions: { label: string; value: string; title?: string }[];
}
export interface AccessControlFormData {
+24 -4
View File
@@ -37,15 +37,35 @@ const BackendFields: React.FC = () => {
return getBackendParamsTips(backend);
}, [backend]);
const backendGroupedOptions = useMemo(() => {
const builtInBackends = backendOptions?.filter((item) => item.isBuiltIn);
const customBackends = backendOptions?.filter((item) => !item.isBuiltIn);
const options = [];
if (builtInBackends && builtInBackends.length > 0) {
options.push({
label: intl.formatMessage({ id: 'backend.builtin' }),
options: builtInBackends
});
}
if (customBackends && customBackends.length > 0) {
options.push({
label: intl.formatMessage({ id: 'backend.custom' }),
options: customBackends
});
}
return options;
}, [backendOptions, intl]);
const backendVersions = useMemo(() => {
if (!backend || backend === backendOptionsMap.custom) {
return [];
}
// find the backend item from backendOptions
const backendItem = backendOptions
.flatMap((group) => group.options)
.find((item) => item.value === backend);
const backendItem = backendOptions.find((item) => item.value === backend);
const versions = backendItem?.versions || [];
@@ -105,7 +125,7 @@ const BackendFields: React.FC = () => {
onChange={onBackendChange}
label={intl.formatMessage({ id: 'models.form.backend' })}
description={<TooltipList list={backendTipsList}></TooltipList>}
options={backendOptions}
options={backendGroupedOptions}
optionRender={optionRender}
labelRender={labelRender}
></SealSelect>
+4 -9
View File
@@ -16,7 +16,7 @@ import {
import { backendOptionsMap } from '../config/backend-parameters';
import { FormContext } from '../config/form-context';
import {
BackendGroupOption,
BackendOption,
DeployFormKey,
FormData,
SourceType
@@ -188,7 +188,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
};
};
const updateKVCacheConfig = (backend: string, option: BackendGroupOption) => {
const updateKVCacheConfig = (backend: string, option: BackendOption) => {
if (
!option.isBuiltIn &&
[backendOptionsMap.SGLang, backendOptionsMap.vllm].includes(backend)
@@ -202,15 +202,10 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
return {};
};
const handleBackendChange = async (
val: string,
option: BackendGroupOption
) => {
console.log('handleBackendChange option===>', val, option);
const isGGUF = checkIsGGUF();
const handleBackendChange = async (val: string, option: BackendOption) => {
form.setFieldsValue({
env: null,
backend_version: option.default_version || '',
backend_version: '', // don't set default version here, let the user select it
backend_parameters: option.default_backend_param || [],
...updateKVCacheConfig(val, option),
...updateGPUSelector(val)
+1 -3
View File
@@ -3,7 +3,6 @@ import SealInputNumber from '@/components/seal-form/input-number';
import { useIntl } from '@umijs/max';
import { Form } from 'antd';
import { useMemo, useRef } from 'react';
import { DeployFormKeyMap } from '../config';
import { backendOptionsMap } from '../config/backend-parameters';
import { useFormContext } from '../config/form-context';
import { FormData } from '../config/types';
@@ -36,9 +35,8 @@ const KVCacheForm = () => {
(item) => item.value === backend
);
// FIXMEremove formKey check after all built-in backends support KV cache
return (
(currentBackend?.isBuiltIn || formKey === DeployFormKeyMap.CATALOG) &&
currentBackend?.isBuiltIn &&
[backendOptionsMap.SGLang, backendOptionsMap.vllm].includes(
backend as string
)
+3 -21
View File
@@ -3,7 +3,7 @@ import { useIntl } from '@umijs/max';
import { useAtom } from 'jotai';
import { queryBackendList } from '../apis';
import { backendOptionsMap } from '../config/backend-parameters';
import { BackendGroupOption } from '../config/types';
import { BackendOption } from '../config/types';
export default function useQueryBackends() {
const [backendOptions, setBackendOptions] = useAtom(backendOptionsAtom);
@@ -12,7 +12,7 @@ export default function useQueryBackends() {
const getBackendOptions = async (params?: { cluster_id: number }) => {
try {
const res = await queryBackendList(params);
const list: BackendGroupOption[] = res?.items?.map((item) => {
const list: BackendOption[] = res?.items?.map((item) => {
return {
value: item.backend_name,
label:
@@ -33,27 +33,9 @@ export default function useQueryBackends() {
}))
};
});
const builtInBackends = list?.filter((item) => item.isBuiltIn);
const customBackends = list?.filter((item) => !item.isBuiltIn);
const options = [];
if (builtInBackends && builtInBackends.length > 0) {
options.push({
label: intl.formatMessage({ id: 'backend.builtin' }),
options: builtInBackends
});
}
if (customBackends && customBackends.length > 0) {
options.push({
label: intl.formatMessage({ id: 'backend.custom' }),
options: customBackends
});
}
if (res?.items) {
setBackendOptions(options);
setBackendOptions(list);
}
return list || [];
} catch (error) {