chore: quick create route

This commit is contained in:
jialin
2026-02-12 12:20:05 +08:00
parent b21fe0ac4c
commit 07664b5f22
21 changed files with 202 additions and 47 deletions
+6
View File
@@ -0,0 +1,6 @@
import { atom } from 'jotai';
export const registerRouteConfigAtom = atom<Record<string, any>>({
initialValues: null,
create: false
});
@@ -96,8 +96,6 @@ const SealTextArea: React.FC<InputTextareaProps & SealFormItemProps> = (
onInput?.(e); onInput?.(e);
}; };
console.log('style=========', style, rest);
return ( return (
<InputWrapper className="textarea-input-wrapper"> <InputWrapper className="textarea-input-wrapper">
<Wrapper <Wrapper
+2 -2
View File
@@ -52,9 +52,9 @@ export default {
'clusters.addworker.nvidiaNotes-02': 'clusters.addworker.nvidiaNotes-02':
'If a model directory already exists on the worker, you can specify the path to mount it.', 'If a model directory already exists on the worker, you can specify the path to mount it.',
'clusters.addworker.hygonNotes': `If <span class="bold-text">/opt/hyhal</span> or <span class="bold-text">/opt/dtk</span> does not exist, create symbolic links pointing to the corresponding Hygon installation paths, for example: <span class="desc-fill">ln -s /path/to/hyhal /opt/hyhal</span> <span class="desc-fill">ln -s /path/to/dtk /opt/dtk</span>.`, 'clusters.addworker.hygonNotes': `If <span class="bold-text">/opt/hyhal</span> or <span class="bold-text">/opt/dtk</span> does not exist, create symbolic links pointing to the corresponding Hygon installation paths, for example: <span class="desc-fill">ln -s /path/to/hyhal /opt/hyhal</span> <span class="desc-fill">ln -s /path/to/dtk /opt/dtk</span>.`,
'clusters.addworker.corexNotes': `If the <span class="bold-text">/lib/modules</span> directory does not exist, create a symbolic link to the Iluvatar installation path: 'clusters.addworker.corexNotes': `If the <span class="bold-text">/lib/modules</span> directory does not exist, create a symbolic link to the Iluvatar SDK installation path:
<span class="bold-text">ln -s /path/to/corex /lib/modules</span>. Same applies to the <span class="bold-text">/usr/local/corex</span> directory.`, <span class="bold-text">ln -s /path/to/corex /lib/modules</span>. Same applies to the <span class="bold-text">/usr/local/corex</span> directory.`,
'clusters.addworker.metaxNotes': `If the <span class="bold-text">/opt/mxdriver</span> directory does not exist, create a symbolic link to the MetaX installation path: 'clusters.addworker.metaxNotes': `If the <span class="bold-text">/opt/mxdriver</span> directory does not exist, create a symbolic link to the MetaX driver and SDK installation path:
<span class="bold-text">ln -s /path/to/metax /opt/mxdriver</span>. Same applies to the <span class="bold-text">/opt/maca</span> directory.`, <span class="bold-text">ln -s /path/to/metax /opt/mxdriver</span>. Same applies to the <span class="bold-text">/opt/maca</span> directory.`,
'clusters.addworker.cambriconNotes': `If the <span class="bold-text">/usr/local/neuware</span> directory does not exist, create a symbolic link to the Cambricon installation path: 'clusters.addworker.cambriconNotes': `If the <span class="bold-text">/usr/local/neuware</span> directory does not exist, create a symbolic link to the Cambricon installation path:
<span class="bold-text">ln -s /path/to/neuware /usr/local/neuware</span>.`, <span class="bold-text">ln -s /path/to/neuware /usr/local/neuware</span>.`,
+2 -1
View File
@@ -22,5 +22,6 @@ export default {
'providers.form.rules.models': 'Please select at least one model', 'providers.form.rules.models': 'Please select at least one model',
'providers.form.rules.tokens': 'Please enter a valid API Key', 'providers.form.rules.tokens': 'Please enter a valid API Key',
'providers.form.rules.model': 'Please select a model', 'providers.form.rules.model': 'Please select a model',
'providers.form.model.duplicate': 'Duplicate model exists' 'providers.form.model.duplicate': 'Duplicate model exists',
'providers.table.registerRoute': 'Register Route'
}; };
+4 -4
View File
@@ -52,9 +52,9 @@ export default {
'clusters.addworker.nvidiaNotes-02': 'clusters.addworker.nvidiaNotes-02':
'If a model directory already exists on the worker, you can specify the path to mount it.', 'If a model directory already exists on the worker, you can specify the path to mount it.',
'clusters.addworker.hygonNotes': `If <span class="bold-text">/opt/hyhal</span> or <span class="bold-text">/opt/dtk</span> does not exist, create symbolic links pointing to the corresponding Hygon installation paths, for example: <span class="desc-fill">ln -s /path/to/hyhal /opt/hyhal</span> <span class="desc-fill">ln -s /path/to/dtk /opt/dtk</span>.`, 'clusters.addworker.hygonNotes': `If <span class="bold-text">/opt/hyhal</span> or <span class="bold-text">/opt/dtk</span> does not exist, create symbolic links pointing to the corresponding Hygon installation paths, for example: <span class="desc-fill">ln -s /path/to/hyhal /opt/hyhal</span> <span class="desc-fill">ln -s /path/to/dtk /opt/dtk</span>.`,
'clusters.addworker.corexNotes': `If the <span class="bold-text">/lib/modules</span> directory does not exist, create a symbolic link to the Iluvatar installation path: 'clusters.addworker.corexNotes': `If the <span class="bold-text">/lib/modules</span> directory does not exist, create a symbolic link to the Iluvatar SDK installation path:
<span class="bold-text">ln -s /path/to/corex /lib/modules</span>. Same applies to the <span class="bold-text">/usr/local/corex</span> directory.`, <span class="bold-text">ln -s /path/to/corex /lib/modules</span>. Same applies to the <span class="bold-text">/usr/local/corex</span> directory.`,
'clusters.addworker.metaxNotes': `If the <span class="bold-text">/opt/mxdriver</span> directory does not exist, create a symbolic link to the MetaX installation path: 'clusters.addworker.metaxNotes': `If the <span class="bold-text">/opt/mxdriver</span> directory does not exist, create a symbolic link to the MetaX driver and SDK installation path:
<span class="bold-text">ln -s /path/to/metax /opt/mxdriver</span>. Same applies to the <span class="bold-text">/opt/maca</span> directory.`, <span class="bold-text">ln -s /path/to/metax /opt/mxdriver</span>. Same applies to the <span class="bold-text">/opt/maca</span> directory.`,
'clusters.addworker.cambriconNotes': `If the <span class="bold-text">/usr/local/neuware</span> directory does not exist, create a symbolic link to the Cambricon installation path: 'clusters.addworker.cambriconNotes': `If the <span class="bold-text">/usr/local/neuware</span> directory does not exist, create a symbolic link to the Cambricon installation path:
<span class="bold-text">ln -s /path/to/neuware /usr/local/neuware</span>.`, <span class="bold-text">ln -s /path/to/neuware /usr/local/neuware</span>.`,
@@ -179,8 +179,8 @@ export default {
// 44. 'clusters.addworker.nvidiaNotes-01': 'If multiple outbound IPs exist, specify the one you want the worker to use. Please double-check with <span class="bold-text">hostname -I | xargs -n1</span>.', // 44. 'clusters.addworker.nvidiaNotes-01': 'If multiple outbound IPs exist, specify the one you want the worker to use. Please double-check with <span class="bold-text">hostname -I | xargs -n1</span>.',
// 45. 'clusters.addworker.nvidiaNotes-02': 'If a model directory already exists on the worker, you can specify the path to mount it.', // 45. 'clusters.addworker.nvidiaNotes-02': 'If a model directory already exists on the worker, you can specify the path to mount it.',
// 46. 'clusters.addworker.hygonNotes': `If <span class="bold-text">/opt/hyhal</span> or <span class="bold-text">/opt/dtk</span> does not exist, create symbolic links pointing to the corresponding Hygon installation paths, for example: <span class="desc-fill">ln -s /path/to/hyhal /opt/hyhal</span> <span class="desc-fill">ln -s /path/to/dtk /opt/dtk</span>.`, // 46. 'clusters.addworker.hygonNotes': `If <span class="bold-text">/opt/hyhal</span> or <span class="bold-text">/opt/dtk</span> does not exist, create symbolic links pointing to the corresponding Hygon installation paths, for example: <span class="desc-fill">ln -s /path/to/hyhal /opt/hyhal</span> <span class="desc-fill">ln -s /path/to/dtk /opt/dtk</span>.`,
// 47. 'clusters.addworker.corexNotes': 'If the <span class="bold-text">/lib/modules</span> directory does not exist, create a symbolic link to the Iluvatar installation path: <span class="bold-text">ln -s /path/to/corex /lib/modules</span>. Same applies to the <span class="bold-text">/usr/local/corex</span> directory.', // 47. 'clusters.addworker.corexNotes': 'If the <span class="bold-text">/lib/modules</span> directory does not exist, create a symbolic link to the Iluvatar SDK installation path: <span class="bold-text">ln -s /path/to/corex /lib/modules</span>. Same applies to the <span class="bold-text">/usr/local/corex</span> directory.',
// 48. 'clusters.addworker.metaxNotes': 'If the <span class="bold-text">/opt/mxdriver</span> directory does not exist, create a symbolic link to the MetaX installation path: <span class="bold-text">ln -s /path/to/metax /opt/mxdriver</span>. Same applies to the <span class="bold-text">/opt/maca</span> directory.', // 48. 'clusters.addworker.metaxNotes': 'If the <span class="bold-text">/opt/mxdriver</span> directory does not exist, create a symbolic link to the MetaX driver and SDK installation path: <span class="bold-text">ln -s /path/to/metax /opt/mxdriver</span>. Same applies to the <span class="bold-text">/opt/maca</span> directory.',
// 49. 'clusters.addworker.cambriconNotes': 'If the <span class="bold-text">/usr/local/neuware</span> directory does not exist, create a symbolic link to the Cambricon installation path: <span class="bold-text">ln -s /path/to/neuware /usr/local/neuware</span>.' // 49. 'clusters.addworker.cambriconNotes': 'If the <span class="bold-text">/usr/local/neuware</span> directory does not exist, create a symbolic link to the Cambricon installation path: <span class="bold-text">ln -s /path/to/neuware /usr/local/neuware</span>.'
// 50. 'clusters.addworker.hygonNotes-02': 'If device detection fails, try removing <span class="bold-text">--env ROCM_SMI_LIB_PATH=/opt/hyhal/lib</span>.', // 50. 'clusters.addworker.hygonNotes-02': 'If device detection fails, try removing <span class="bold-text">--env ROCM_SMI_LIB_PATH=/opt/hyhal/lib</span>.',
// 51. 'clusters.addworker.selectCluster': 'Select Cluster', // 51. 'clusters.addworker.selectCluster': 'Select Cluster',
+2 -1
View File
@@ -22,5 +22,6 @@ export default {
'providers.form.rules.models': 'Please select at least one model', 'providers.form.rules.models': 'Please select at least one model',
'providers.form.rules.tokens': 'Please enter a valid API Key', 'providers.form.rules.tokens': 'Please enter a valid API Key',
'providers.form.rules.model': 'Please select a model', 'providers.form.rules.model': 'Please select a model',
'providers.form.model.duplicate': 'Duplicate model exists' 'providers.form.model.duplicate': 'Duplicate model exists',
'providers.table.registerRoute': 'Register Route'
}; };
+2 -2
View File
@@ -53,9 +53,9 @@ export default {
'Если директория с моделями уже существует на воркере, вы можете указать путь для её монтирования.', 'Если директория с моделями уже существует на воркере, вы можете указать путь для её монтирования.',
'clusters.addworker.hygonNotes': `If <span class="bold-text">/opt/hyhal</span> or <span class="bold-text">/opt/dtk</span> does not exist, create symbolic links pointing to the corresponding Hygon installation paths, for example: <span class="desc-fill">ln -s /path/to/hyhal /opt/hyhal</span> <span class="desc-fill">ln -s /path/to/dtk /opt/dtk</span>.`, 'clusters.addworker.hygonNotes': `If <span class="bold-text">/opt/hyhal</span> or <span class="bold-text">/opt/dtk</span> does not exist, create symbolic links pointing to the corresponding Hygon installation paths, for example: <span class="desc-fill">ln -s /path/to/hyhal /opt/hyhal</span> <span class="desc-fill">ln -s /path/to/dtk /opt/dtk</span>.`,
'clusters.addworker.corexNotes': 'clusters.addworker.corexNotes':
'Если директория <span class="bold-text">/lib/modules</span> не существует, создайте символическую ссылку на путь установки Iluvatar: <span class="bold-text">ln -s /path/to/corex /lib/modules</span>. Аналогично для директории <span class="bold-text">/usr/local/corex</span>.', 'Если директория <span class="bold-text">/lib/modules</span> не существует, создайте символическую ссылку на путь установки Iluvatar SDK: <span class="bold-text">ln -s /path/to/corex /lib/modules</span>. Аналогично для директории <span class="bold-text">/usr/local/corex</span>.',
'clusters.addworker.metaxNotes': 'clusters.addworker.metaxNotes':
'Если директория <span class="bold-text">/opt/mxdriver</span> не существует, создайте символическую ссылку на путь установки MetaX: <span class="bold-text">ln -s /path/to/metax /opt/mxdriver</span>. Аналогично для директории <span class="bold-text">/opt/maca</span>.', 'Если директория <span class="bold-text">/opt/mxdriver</span> не существует, создайте символическую ссылку на путь установки MetaX SDK: <span class="bold-text">ln -s /path/to/metax /opt/mxdriver</span>. Аналогично для директории <span class="bold-text">/opt/maca</span>.',
'clusters.addworker.cambriconNotes': 'clusters.addworker.cambriconNotes':
'Если директория <span class="bold-text">/usr/local/neuware</span> не существует, создайте символическую ссылку на путь установки Cambricon: <span class="bold-text">ln -s /path/to/neuware /usr/local/neuware</span>.', 'Если директория <span class="bold-text">/usr/local/neuware</span> не существует, создайте символическую ссылку на путь установки Cambricon: <span class="bold-text">ln -s /path/to/neuware /usr/local/neuware</span>.',
'clusters.addworker.hygonNotes-02': 'clusters.addworker.hygonNotes-02':
+2 -1
View File
@@ -22,5 +22,6 @@ export default {
'providers.form.rules.models': 'Please select at least one model', 'providers.form.rules.models': 'Please select at least one model',
'providers.form.rules.tokens': 'Please enter a valid API Key', 'providers.form.rules.tokens': 'Please enter a valid API Key',
'providers.form.rules.model': 'Please select a model', 'providers.form.rules.model': 'Please select a model',
'providers.form.model.duplicate': 'Duplicate model exists' 'providers.form.model.duplicate': 'Duplicate model exists',
'providers.table.registerRoute': 'Register Route'
}; };
+2 -2
View File
@@ -53,9 +53,9 @@ export default {
<span class="desc-fill line-6">ln -s /path/to/hyhal /opt/hyhal</span> <span class="desc-fill line-6">ln -s /path/to/hyhal /opt/hyhal</span>
<span class="desc-fill line-6">ln -s /path/to/dtk /opt/dtk</span>`, <span class="desc-fill line-6">ln -s /path/to/dtk /opt/dtk</span>`,
'clusters.addworker.corexNotes': 'clusters.addworker.corexNotes':
'如果 <span class="bold-text">/lib/modules</span> 目录不存在,请创建指向天数智芯安装路径的符号链接:<span class="bold-text">ln -s /path/to/corex /lib/modules</span>。与 <span class="bold-text">/usr/local/corex</span> 目录相同。', '如果 <span class="bold-text">/lib/modules</span> 目录不存在,请创建指向天数智芯 SDK 安装路径的符号链接:<span class="bold-text">ln -s /path/to/corex /lib/modules</span>。与 <span class="bold-text">/usr/local/corex</span> 目录相同。',
'clusters.addworker.metaxNotes': 'clusters.addworker.metaxNotes':
'如果 <span class="bold-text">/opt/mxdriver</span> 目录不存在,请创建指向沐曦安装路径的符号链接:<span class="bold-text">ln -s /path/to/metax /opt/mxdriver</span>。与 <span class="bold-text">/opt/maca</span> 目录相同。', '如果 <span class="bold-text">/opt/mxdriver</span> 目录不存在,请创建指向沐曦驱动和 SDK 安装路径的符号链接:<span class="bold-text">ln -s /path/to/metax /opt/mxdriver</span>。与 <span class="bold-text">/opt/maca</span> 目录相同。',
'clusters.addworker.cambriconNotes': 'clusters.addworker.cambriconNotes':
'如果 <span class="bold-text">/usr/local/neuware</span> 目录不存在,请创建指向寒武纪安装路径的符号链接:<span class="bold-text">ln -s /path/to/neuware /usr/local/neuware</span>。', '如果 <span class="bold-text">/usr/local/neuware</span> 目录不存在,请创建指向寒武纪安装路径的符号链接:<span class="bold-text">ln -s /path/to/neuware /usr/local/neuware</span>。',
'clusters.addworker.hygonNotes-02': 'clusters.addworker.hygonNotes-02':
+2 -1
View File
@@ -22,5 +22,6 @@ export default {
'providers.form.rules.models': '请选择至少一个模型', 'providers.form.rules.models': '请选择至少一个模型',
'providers.form.rules.tokens': '请输入有效的 API Key', 'providers.form.rules.tokens': '请输入有效的 API Key',
'providers.form.rules.model': '请选择模型', 'providers.form.rules.model': '请选择模型',
'providers.form.model.duplicate': '存在相同的模型' 'providers.form.model.duplicate': '存在相同的模型',
'providers.table.registerRoute': '注册路由'
}; };
+5
View File
@@ -30,6 +30,11 @@ export const rowActionList = [
label: 'common.button.edit', label: 'common.button.edit',
icon: icons.EditOutlined icon: icons.EditOutlined
}, },
{
key: 'registerRoute',
label: 'providers.table.registerRoute',
icon: icons.CaptivePortal
},
{ {
key: 'copy', key: 'copy',
label: 'common.button.clone', label: 'common.button.clone',
@@ -98,7 +98,7 @@ const SupportedModels = () => {
if (!value || value.length === 0) { if (!value || value.length === 0) {
return Promise.reject( return Promise.reject(
new Error( new Error(
getRuleMessage('input', 'providers.form.rules.models') intl.formatMessage({ id: 'providers.form.rules.models' })
) )
); );
} }
@@ -106,7 +106,7 @@ const SupportedModels = () => {
if (value.some((item: ProviderModel) => !item.name)) { if (value.some((item: ProviderModel) => !item.name)) {
return Promise.reject( return Promise.reject(
new Error( new Error(
getRuleMessage('select', 'providers.form.rules.model') intl.formatMessage({ id: 'providers.form.rules.model' })
) )
); );
} }
@@ -1,10 +1,10 @@
// columns.ts // columns.ts
import AutoTooltip from '@/components/auto-tooltip'; import AutoTooltip from '@/components/auto-tooltip';
import DropdownButtons from '@/components/drop-down-buttons'; import DropdownButtons from '@/components/drop-down-buttons';
import { SealColumnProps } from '@/components/seal-table/types';
import { tableSorter } from '@/config/settings'; import { tableSorter } from '@/config/settings';
import { useIntl } from '@umijs/max'; import { useIntl } from '@umijs/max';
import { Tag } from 'antd'; import { Tag } from 'antd';
import { ColumnsType } from 'antd/lib/table';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { useMemo } from 'react'; import { useMemo } from 'react';
import ProviderLogo from '../components/provider-logo'; import ProviderLogo from '../components/provider-logo';
@@ -16,10 +16,18 @@ import { MaasProviderItem, ProviderModel } from '../config/types';
const useProviderColumns = ( const useProviderColumns = (
handleSelect: (val: string, record: MaasProviderItem) => void, handleSelect: (val: string, record: MaasProviderItem) => void,
onCellClick?: (record: MaasProviderItem, dataIndex: string) => void onCellClick?: (record: MaasProviderItem, dataIndex: string) => void
): SealColumnProps[] => { ): ColumnsType<MaasProviderItem> => {
const intl = useIntl(); const intl = useIntl();
return useMemo(() => { return useMemo(() => {
const setActionList = (record: MaasProviderItem) => {
return rowActionList.filter((action) => {
if (action.key === 'registerRoute') {
return record.models && record.models.length > 0;
}
return true;
});
};
return [ return [
{ {
title: intl.formatMessage({ id: 'common.table.name' }), title: intl.formatMessage({ id: 'common.table.name' }),
@@ -84,7 +92,7 @@ const useProviderColumns = (
minWidth: 120, minWidth: 120,
render: (value: string, record: MaasProviderItem) => ( render: (value: string, record: MaasProviderItem) => (
<DropdownButtons <DropdownButtons
items={rowActionList} items={setActionList(record)}
onSelect={(val) => handleSelect(val, record)} onSelect={(val) => handleSelect(val, record)}
></DropdownButtons> ></DropdownButtons>
) )
@@ -0,0 +1,36 @@
import { registerRouteConfigAtom } from '@/atoms/routes';
import { modelCategoriesMap } from '@/pages/llmodels/config';
import { useNavigate } from '@umijs/max';
import { useAtom } from 'jotai';
const useRegisterRoute = () => {
const navigate = useNavigate();
const [, setRegisterRouteConfig] = useAtom(registerRouteConfigAtom);
const handleRegisterRoute = (record: any) => {
const model = record.models?.[0] || {};
const initialValues = {
name: model.name || '',
categories: [model.category || modelCategoriesMap.llm],
routeTargets: [
{
weight: 100,
provider_model_name: model.name,
provider_id: record.id,
parentId: record.id
}
]
};
setRegisterRouteConfig({
initialValues,
create: true
});
navigate('/models/routes');
};
return {
handleRegisterRoute
};
};
export default useRegisterRoute;
+6 -6
View File
@@ -1,15 +1,12 @@
import { expandKeysAtom } from '@/atoms/clusters';
import DeleteModal from '@/components/delete-modal'; import DeleteModal from '@/components/delete-modal';
import IconFont from '@/components/icon-font'; import IconFont from '@/components/icon-font';
import { FilterBar } from '@/components/page-tools'; import { FilterBar } from '@/components/page-tools';
import { PageAction } from '@/config'; import { PageAction } from '@/config';
import { TABLE_SORT_DIRECTIONS } from '@/config/settings'; import { TABLE_SORT_DIRECTIONS } from '@/config/settings';
import useExpandedRowKeys from '@/hooks/use-expanded-row-keys';
import useTableFetch from '@/hooks/use-table-fetch'; import useTableFetch from '@/hooks/use-table-fetch';
import { useIntl } from '@umijs/max'; import { useIntl } from '@umijs/max';
import { useMemoizedFn } from 'ahooks'; import { useMemoizedFn } from 'ahooks';
import { ConfigProvider, message, Table } from 'antd'; import { ConfigProvider, message, Table } from 'antd';
import { useAtom } from 'jotai';
import _ from 'lodash'; import _ from 'lodash';
import NoResult from '../_components/no-result'; import NoResult from '../_components/no-result';
import PageBox from '../_components/page-box'; import PageBox from '../_components/page-box';
@@ -24,6 +21,7 @@ import AddMaasProvider from './components/add-provider-modal';
import { FormData, MaasProviderItem as ListItem } from './config/types'; import { FormData, MaasProviderItem as ListItem } from './config/types';
import useCreateProvider from './hooks/use-create-provider'; import useCreateProvider from './hooks/use-create-provider';
import useProviderColumns from './hooks/use-provider-columns'; import useProviderColumns from './hooks/use-provider-columns';
import useRegisterRoute from './hooks/use-register-route';
const MaasProvider: React.FC = () => { const MaasProvider: React.FC = () => {
const { const {
@@ -45,10 +43,8 @@ const MaasProvider: React.FC = () => {
API: MAAS_PROVIDERS_API, API: MAAS_PROVIDERS_API,
contentForDelete: 'menu.models.providers' contentForDelete: 'menu.models.providers'
}); });
const [expandAtom] = useAtom(expandKeysAtom);
const { handleExpandChange, handleExpandAll, expandedRowKeys } =
useExpandedRowKeys(expandAtom);
const intl = useIntl(); const intl = useIntl();
const { handleRegisterRoute } = useRegisterRoute();
const { openProviderModalStatus, openProviderModal, closeProviderModal } = const { openProviderModalStatus, openProviderModal, closeProviderModal } =
useCreateProvider({ useCreateProvider({
refresh: handleSearch refresh: handleSearch
@@ -117,6 +113,10 @@ const MaasProvider: React.FC = () => {
} }
); );
} }
if (val === 'registerRoute') {
handleRegisterRoute(row);
}
}); });
const renderEmpty = (type?: string) => { const renderEmpty = (type?: string) => {
@@ -10,6 +10,7 @@ import ModelRouteForm from '../forms';
type AddModalProps = { type AddModalProps = {
title: string; title: string;
action: PageActionType; action: PageActionType;
realAction?: string;
open: boolean; open: boolean;
currentData?: ListItem; // Used when action is EDIT currentData?: ListItem; // Used when action is EDIT
onOk: (values: FormData) => void; onOk: (values: FormData) => void;
@@ -18,6 +19,7 @@ type AddModalProps = {
const AddProvider: React.FC<AddModalProps> = ({ const AddProvider: React.FC<AddModalProps> = ({
title, title,
action, action,
realAction,
open, open,
currentData, currentData,
onOk, onOk,
@@ -75,8 +77,10 @@ const AddProvider: React.FC<AddModalProps> = ({
<ModelRouteForm <ModelRouteForm
ref={form} ref={form}
action={action} action={action}
realAction={realAction}
currentData={currentData} currentData={currentData}
onFinish={onFinish} onFinish={onFinish}
open={open}
onFallbackChange={(changed: boolean) => { onFallbackChange={(changed: boolean) => {
setIsChanged(changed); setIsChanged(changed);
}} }}
@@ -4,6 +4,7 @@ import { createContext, useContext } from 'react';
interface FormContextProps { interface FormContextProps {
onFallbackChange?: (changed: boolean) => void; onFallbackChange?: (changed: boolean) => void;
action?: PageActionType; action?: PageActionType;
realAction?: string;
currentData?: any; currentData?: any;
} }
+57 -16
View File
@@ -4,6 +4,7 @@ import { PageActionType } from '@/config/types';
import CollapsePanel from '@/pages/_components/collapse-panel'; import CollapsePanel from '@/pages/_components/collapse-panel';
import { useWrapperContext } from '@/pages/_components/column-wrapper/use-wrapper-context'; import { useWrapperContext } from '@/pages/_components/column-wrapper/use-wrapper-context';
import ScrollSpyTabs from '@/pages/_components/scroll-spy-tabs'; import ScrollSpyTabs from '@/pages/_components/scroll-spy-tabs';
import { modelCategoriesMap } from '@/pages/llmodels/config';
import { useIntl } from '@umijs/max'; import { useIntl } from '@umijs/max';
import { Form } from 'antd'; import { Form } from 'antd';
import _ from 'lodash'; import _ from 'lodash';
@@ -22,8 +23,17 @@ import Targets from './targets';
interface ProviderFormProps { interface ProviderFormProps {
ref?: any; ref?: any;
open: boolean;
action: PageActionType; action: PageActionType;
currentData?: ListItem; // Used when action is EDIT realAction?: string;
currentData?: ListItem & {
routeTargets?: {
weight?: number;
model_id?: number;
provider_id?: number;
provider_model_name?: string;
}[];
}; // Used when action is EDIT
onFinish: (values: FormData) => Promise<void>; onFinish: (values: FormData) => Promise<void>;
onFallbackChange?: (changed: boolean) => void; onFallbackChange?: (changed: boolean) => void;
} }
@@ -36,14 +46,16 @@ const TABKeysMap = {
}; };
const AccessForm: React.FC<ProviderFormProps> = forwardRef((props, ref) => { const AccessForm: React.FC<ProviderFormProps> = forwardRef((props, ref) => {
const { action, currentData, onFinish, onFallbackChange } = props;
const intl = useIntl(); const intl = useIntl();
const { action, realAction, currentData, open, onFinish, onFallbackChange } =
props;
const { getScrollElementScrollableHeight } = useWrapperContext(); const { getScrollElementScrollableHeight } = useWrapperContext();
const [activeKey, setActiveKey] = useState<string[]>([TABKeysMap.BASIC]); const [activeKey, setActiveKey] = useState<string[]>([TABKeysMap.BASIC]);
const [form] = Form.useForm(); const [form] = Form.useForm();
const scrollTabsRef = useRef<any>(null); const scrollTabsRef = useRef<any>(null);
const targetsRef = useRef<any>(null); const targetsRef = useRef<any>(null);
const { generateTargetData, fetchTargets } = useEditTargets(); const { generateTargetData, fetchTargets } = useEditTargets();
const segmentOptions = [ const segmentOptions = [
{ {
value: TABKeysMap.BASIC, value: TABKeysMap.BASIC,
@@ -117,7 +129,32 @@ const AccessForm: React.FC<ProviderFormProps> = forwardRef((props, ref) => {
setActiveKey(Array.isArray(keys) ? keys : [keys]); setActiveKey(Array.isArray(keys) ? keys : [keys]);
}; };
// init form values
useEffect(() => { useEffect(() => {
if (!open) {
form.resetFields();
return;
}
const initDataList = async (
targets: {
weight?: number;
model_id?: number;
provider_id?: number;
provider_model_name?: string;
}[]
) => {
// init targets form list
targetsRef.current?.initDataList(
targets?.map((ep) => ({
weight: ep.weight,
value: ep.model_id
? ['deployments', ep.model_id]
: [ep.provider_id, ep.provider_model_name]
})) || []
);
};
const initEditionForm = async () => { const initEditionForm = async () => {
const targetList = await fetchTargets(currentData!.id); const targetList = await fetchTargets(currentData!.id);
const { targets, fallbackTarget } = generateTargetData(targetList); const { targets, fallbackTarget } = generateTargetData(targetList);
@@ -129,15 +166,7 @@ const AccessForm: React.FC<ProviderFormProps> = forwardRef((props, ref) => {
fallback_target: fallbackTarget fallback_target: fallbackTarget
}); });
// init targets form list initDataList(targets);
targetsRef.current?.initDataList(
targets?.map((ep) => ({
weight: ep.weight,
value: ep.model_id
? ['deployments', ep.model_id]
: [ep.provider_id, ep.provider_model_name]
})) || []
);
// init fallback value // init fallback value
if (fallbackTarget) { if (fallbackTarget) {
@@ -148,12 +177,22 @@ const AccessForm: React.FC<ProviderFormProps> = forwardRef((props, ref) => {
}); });
} }
}; };
const initRegisterForm = () => {
form.setFieldsValue({
...currentData,
targets: currentData?.routeTargets || []
});
initDataList(currentData?.routeTargets || []);
};
// --- register from provider page ---
if (action === PageAction.EDIT && currentData) { if (action === PageAction.EDIT && currentData) {
initEditionForm(); initEditionForm();
} else { } else if (realAction === 'register' && currentData) {
form.resetFields(); initRegisterForm();
} }
}, [action, currentData, form]); }, [action, currentData, form, open, realAction]);
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
submit: () => { submit: () => {
@@ -177,12 +216,14 @@ const AccessForm: React.FC<ProviderFormProps> = forwardRef((props, ref) => {
}} }}
getScrollElementScrollableHeight={getScrollElementScrollableHeight} getScrollElementScrollableHeight={getScrollElementScrollableHeight}
> >
<FormContext.Provider value={{ onFallbackChange, action, currentData }}> <FormContext.Provider
value={{ onFallbackChange, action, realAction, currentData }}
>
<Form <Form
form={form} form={form}
onFinish={handleOnFinish} onFinish={handleOnFinish}
initialValues={{ initialValues={{
categories: [], categories: [modelCategoriesMap.llm],
meta: {} meta: {}
}} }}
> >
+7
View File
@@ -102,6 +102,7 @@ const TargetsForm = forwardRef((props, ref) => {
value: [] value: []
} }
]; ];
form.setFieldValue('targets', newTargets); form.setFieldValue('targets', newTargets);
}; };
@@ -239,6 +240,12 @@ const TargetsForm = forwardRef((props, ref) => {
fetchSourceModels(); fetchSourceModels();
}, []); }, []);
useEffect(() => {
if (action === PageAction.CREATE) {
handleOnAdd();
}
}, [action]);
return ( return (
<> <>
<Form.Item <Form.Item
@@ -11,10 +11,12 @@ const useCreateRoute = (options?: { refresh: () => void }) => {
action: PageActionType; action: PageActionType;
currentData?: ListItem; currentData?: ListItem;
title: string; title: string;
realAction?: string;
}>({ }>({
open: false, open: false,
action: PageAction.CREATE, action: PageAction.CREATE,
currentData: undefined, currentData: undefined,
realAction: undefined,
title: '' title: ''
}); });
@@ -32,6 +34,21 @@ const useCreateRoute = (options?: { refresh: () => void }) => {
saveScrollHeight(); saveScrollHeight();
}; };
const registerRoute = (
action: PageActionType,
title: string,
currentData?: ListItem
) => {
setOpenModalStatus({
open: true,
action,
realAction: 'register',
currentData,
title: title
});
saveScrollHeight();
};
const closeModal = () => { const closeModal = () => {
setOpenModalStatus({ setOpenModalStatus({
open: false, open: false,
@@ -46,6 +63,7 @@ const useCreateRoute = (options?: { refresh: () => void }) => {
openRouteModalStatus: openModalStatus, openRouteModalStatus: openModalStatus,
setOpenRouteModalStatus: setOpenModalStatus, setOpenRouteModalStatus: setOpenModalStatus,
openRouteModal: openModal, openRouteModal: openModal,
registerRouteModal: registerRoute,
closeRouteModal: closeModal closeRouteModal: closeModal
}; };
}; };
+31 -4
View File
@@ -1,4 +1,5 @@
import { expandKeysAtom } from '@/atoms/clusters'; import { expandKeysAtom } from '@/atoms/clusters';
import { registerRouteConfigAtom } from '@/atoms/routes';
import DeleteModal from '@/components/delete-modal'; import DeleteModal from '@/components/delete-modal';
import IconFont from '@/components/icon-font'; import IconFont from '@/components/icon-font';
import { FilterBar } from '@/components/page-tools'; import { FilterBar } from '@/components/page-tools';
@@ -73,8 +74,12 @@ const ModelRoutes: React.FC = () => {
expandedRowKeys expandedRowKeys
} = useExpandedRowKeys(expandAtom); } = useExpandedRowKeys(expandAtom);
const intl = useIntl(); const intl = useIntl();
const { openRouteModalStatus, openRouteModal, closeRouteModal } = const {
useCreateRoute(); openRouteModalStatus,
openRouteModal,
registerRouteModal,
closeRouteModal
} = useCreateRoute();
const { const {
openAccessControlModal, openAccessControlModal,
closeAccessControlModal, closeAccessControlModal,
@@ -83,6 +88,9 @@ const ModelRoutes: React.FC = () => {
const { sourceModels, fetchSourceModels } = useTargetSourceModels(); const { sourceModels, fetchSourceModels } = useTargetSourceModels();
const { handleOpenPlayGround } = useOpenPlayground(); const { handleOpenPlayGround } = useOpenPlayground();
const { apiAccessInfo, openViewAPIInfo, closeViewAPIInfo } = useViewApIInfo(); const { apiAccessInfo, openViewAPIInfo, closeViewAPIInfo } = useViewApIInfo();
const [registerRouteConfig, setRegisterRouteConfig] = useAtom(
registerRouteConfigAtom
);
const [modelList, setModelsList] = useState<Global.BaseOption<number>[]>([]); const [modelList, setModelsList] = useState<Global.BaseOption<number>[]>([]);
useEffect(() => { useEffect(() => {
@@ -102,6 +110,14 @@ const ModelRoutes: React.FC = () => {
fetchModels(); fetchModels();
}, []); }, []);
const handleCloseRouteModal = () => {
closeRouteModal();
setRegisterRouteConfig({
initialValues: null,
create: false
});
};
const handleClickDropdown = () => { const handleClickDropdown = () => {
openRouteModal( openRouteModal(
PageAction.CREATE, PageAction.CREATE,
@@ -131,14 +147,14 @@ const ModelRoutes: React.FC = () => {
updateExpandedRowKeys([data.id, ...expandedRowKeys]); updateExpandedRowKeys([data.id, ...expandedRowKeys]);
} }
fetchData(); fetchData();
closeRouteModal(); handleCloseRouteModal();
message.success(intl.formatMessage({ id: 'common.message.success' })); message.success(intl.formatMessage({ id: 'common.message.success' }));
} catch (error) {} } catch (error) {}
}; };
const handleModalCancel = () => { const handleModalCancel = () => {
console.log('handleModalCancel'); console.log('handleModalCancel');
closeRouteModal(); handleCloseRouteModal();
}; };
const handleEditProvider = (row: ListItem) => { const handleEditProvider = (row: ListItem) => {
@@ -247,6 +263,16 @@ const ModelRoutes: React.FC = () => {
fetchSourceModels(); fetchSourceModels();
}, []); }, []);
useEffect(() => {
if (registerRouteConfig.create && dataSource.loadend) {
registerRouteModal(
PageAction.CREATE,
intl.formatMessage({ id: 'routes.button.add' }),
registerRouteConfig.initialValues
);
}
}, [registerRouteConfig, dataSource.loadend]);
const columns = useRoutesColumns(handleSelect); const columns = useRoutesColumns(handleSelect);
return ( return (
@@ -318,6 +344,7 @@ const ModelRoutes: React.FC = () => {
</PageBox> </PageBox>
<AddRouteModal <AddRouteModal
open={openRouteModalStatus.open} open={openRouteModalStatus.open}
realAction={openRouteModalStatus.realAction}
action={openRouteModalStatus.action} action={openRouteModalStatus.action}
title={openRouteModalStatus.title} title={openRouteModalStatus.title}
currentData={openRouteModalStatus.currentData} currentData={openRouteModalStatus.currentData}