fix: backend option format
This commit is contained in:
@@ -299,8 +299,13 @@ export interface BackendGroupOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface BackendOption {
|
export interface BackendOption {
|
||||||
|
value: string;
|
||||||
label: 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 {
|
export interface AccessControlFormData {
|
||||||
|
|||||||
@@ -37,15 +37,35 @@ const BackendFields: React.FC = () => {
|
|||||||
return getBackendParamsTips(backend);
|
return getBackendParamsTips(backend);
|
||||||
}, [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(() => {
|
const backendVersions = useMemo(() => {
|
||||||
if (!backend || backend === backendOptionsMap.custom) {
|
if (!backend || backend === backendOptionsMap.custom) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the backend item from backendOptions
|
// find the backend item from backendOptions
|
||||||
const backendItem = backendOptions
|
const backendItem = backendOptions.find((item) => item.value === backend);
|
||||||
.flatMap((group) => group.options)
|
|
||||||
.find((item) => item.value === backend);
|
|
||||||
|
|
||||||
const versions = backendItem?.versions || [];
|
const versions = backendItem?.versions || [];
|
||||||
|
|
||||||
@@ -105,7 +125,7 @@ const BackendFields: React.FC = () => {
|
|||||||
onChange={onBackendChange}
|
onChange={onBackendChange}
|
||||||
label={intl.formatMessage({ id: 'models.form.backend' })}
|
label={intl.formatMessage({ id: 'models.form.backend' })}
|
||||||
description={<TooltipList list={backendTipsList}></TooltipList>}
|
description={<TooltipList list={backendTipsList}></TooltipList>}
|
||||||
options={backendOptions}
|
options={backendGroupedOptions}
|
||||||
optionRender={optionRender}
|
optionRender={optionRender}
|
||||||
labelRender={labelRender}
|
labelRender={labelRender}
|
||||||
></SealSelect>
|
></SealSelect>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
import { backendOptionsMap } from '../config/backend-parameters';
|
import { backendOptionsMap } from '../config/backend-parameters';
|
||||||
import { FormContext } from '../config/form-context';
|
import { FormContext } from '../config/form-context';
|
||||||
import {
|
import {
|
||||||
BackendGroupOption,
|
BackendOption,
|
||||||
DeployFormKey,
|
DeployFormKey,
|
||||||
FormData,
|
FormData,
|
||||||
SourceType
|
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 (
|
if (
|
||||||
!option.isBuiltIn &&
|
!option.isBuiltIn &&
|
||||||
[backendOptionsMap.SGLang, backendOptionsMap.vllm].includes(backend)
|
[backendOptionsMap.SGLang, backendOptionsMap.vllm].includes(backend)
|
||||||
@@ -202,15 +202,10 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
|
|||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBackendChange = async (
|
const handleBackendChange = async (val: string, option: BackendOption) => {
|
||||||
val: string,
|
|
||||||
option: BackendGroupOption
|
|
||||||
) => {
|
|
||||||
console.log('handleBackendChange option===>', val, option);
|
|
||||||
const isGGUF = checkIsGGUF();
|
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
env: null,
|
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 || [],
|
backend_parameters: option.default_backend_param || [],
|
||||||
...updateKVCacheConfig(val, option),
|
...updateKVCacheConfig(val, option),
|
||||||
...updateGPUSelector(val)
|
...updateGPUSelector(val)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import SealInputNumber from '@/components/seal-form/input-number';
|
|||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Form } from 'antd';
|
import { Form } from 'antd';
|
||||||
import { useMemo, useRef } from 'react';
|
import { useMemo, useRef } from 'react';
|
||||||
import { DeployFormKeyMap } from '../config';
|
|
||||||
import { backendOptionsMap } from '../config/backend-parameters';
|
import { backendOptionsMap } from '../config/backend-parameters';
|
||||||
import { useFormContext } from '../config/form-context';
|
import { useFormContext } from '../config/form-context';
|
||||||
import { FormData } from '../config/types';
|
import { FormData } from '../config/types';
|
||||||
@@ -36,9 +35,8 @@ const KVCacheForm = () => {
|
|||||||
(item) => item.value === backend
|
(item) => item.value === backend
|
||||||
);
|
);
|
||||||
|
|
||||||
// FIXME:remove formKey check after all built-in backends support KV cache
|
|
||||||
return (
|
return (
|
||||||
(currentBackend?.isBuiltIn || formKey === DeployFormKeyMap.CATALOG) &&
|
currentBackend?.isBuiltIn &&
|
||||||
[backendOptionsMap.SGLang, backendOptionsMap.vllm].includes(
|
[backendOptionsMap.SGLang, backendOptionsMap.vllm].includes(
|
||||||
backend as string
|
backend as string
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useIntl } from '@umijs/max';
|
|||||||
import { useAtom } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
import { queryBackendList } from '../apis';
|
import { queryBackendList } from '../apis';
|
||||||
import { backendOptionsMap } from '../config/backend-parameters';
|
import { backendOptionsMap } from '../config/backend-parameters';
|
||||||
import { BackendGroupOption } from '../config/types';
|
import { BackendOption } from '../config/types';
|
||||||
|
|
||||||
export default function useQueryBackends() {
|
export default function useQueryBackends() {
|
||||||
const [backendOptions, setBackendOptions] = useAtom(backendOptionsAtom);
|
const [backendOptions, setBackendOptions] = useAtom(backendOptionsAtom);
|
||||||
@@ -12,7 +12,7 @@ export default function useQueryBackends() {
|
|||||||
const getBackendOptions = async (params?: { cluster_id: number }) => {
|
const getBackendOptions = async (params?: { cluster_id: number }) => {
|
||||||
try {
|
try {
|
||||||
const res = await queryBackendList(params);
|
const res = await queryBackendList(params);
|
||||||
const list: BackendGroupOption[] = res?.items?.map((item) => {
|
const list: BackendOption[] = res?.items?.map((item) => {
|
||||||
return {
|
return {
|
||||||
value: item.backend_name,
|
value: item.backend_name,
|
||||||
label:
|
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) {
|
if (res?.items) {
|
||||||
setBackendOptions(options);
|
setBackendOptions(list);
|
||||||
}
|
}
|
||||||
return list || [];
|
return list || [];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user