fix: default benchmark form values
This commit is contained in:
@@ -3,6 +3,7 @@ import SealSelect from '@/components/seal-form/seal-select';
|
||||
import { PageAction } from '@/config';
|
||||
import useAppUtils from '@/hooks/use-app-utils';
|
||||
import { ClusterStatusValueMap } from '@/pages/cluster-management/config';
|
||||
import { useBenchmarkTargetInstance } from '@/pages/llmodels/hooks/use-run-benchmark';
|
||||
import { useIntl } from '@umijs/max';
|
||||
import { Form } from 'antd';
|
||||
import React, { useEffect } from 'react';
|
||||
@@ -15,6 +16,7 @@ const BasicForm: React.FC = () => {
|
||||
const form = Form.useFormInstance();
|
||||
const { getRuleMessage } = useAppUtils();
|
||||
const { action, open, clusterList } = useFormContext();
|
||||
const { benchmarkTargetInstance } = useBenchmarkTargetInstance();
|
||||
|
||||
useEffect(() => {
|
||||
const initClusterId = (list: any[]) => {
|
||||
@@ -35,9 +37,12 @@ const BasicForm: React.FC = () => {
|
||||
clusterList?.length > 0 &&
|
||||
action === PageAction.CREATE
|
||||
) {
|
||||
form.setFieldValue('cluster_id', initClusterId(clusterList));
|
||||
form.setFieldValue(
|
||||
'cluster_id',
|
||||
benchmarkTargetInstance.cluster_id || initClusterId(clusterList)
|
||||
);
|
||||
}
|
||||
}, [form, action, clusterList]);
|
||||
}, [form, action, clusterList, benchmarkTargetInstance]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -43,14 +43,46 @@ const DatasetForm: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize profile when open form
|
||||
const initProfile = (
|
||||
value: string,
|
||||
option: any,
|
||||
datasetList: Global.BaseOption<number | string>[]
|
||||
) => {
|
||||
if (value !== ProfileValueMap.Custom) {
|
||||
const dataset_id = datasetList.find(
|
||||
(item) => item.label === option.config?.dataset_name
|
||||
)?.value;
|
||||
|
||||
form.setFieldsValue({
|
||||
profile: value,
|
||||
dataset_id: dataset_id,
|
||||
..._.omit(option?.config, ['description', 'dataset_source'])
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) {
|
||||
cancelDatasetRequest();
|
||||
cancelProfilesRequest();
|
||||
}
|
||||
|
||||
if (open) {
|
||||
fetchProfilesData();
|
||||
fetchDatasetData();
|
||||
const init = async () => {
|
||||
const profiles = await fetchProfilesData();
|
||||
const datasets = await fetchDatasetData();
|
||||
// set default profile
|
||||
if (profiles?.length > 0) {
|
||||
const throughputProfile = profiles.find(
|
||||
(item) => item.value === ProfileValueMap.ThroughputMedium
|
||||
);
|
||||
if (throughputProfile) {
|
||||
initProfile(throughputProfile.value, throughputProfile, datasets);
|
||||
}
|
||||
}
|
||||
};
|
||||
init();
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
@@ -73,7 +105,12 @@ const DatasetForm: React.FC = () => {
|
||||
required
|
||||
>
|
||||
{profilesOptions?.map((item: any) => (
|
||||
<Select.Option key={item.value} value={item.value}>
|
||||
<Select.Option
|
||||
key={item.value}
|
||||
value={item.value}
|
||||
label={item.label}
|
||||
config={item.config}
|
||||
>
|
||||
<AutoTooltip
|
||||
ghost
|
||||
showTitle={!!item.tips}
|
||||
|
||||
@@ -37,12 +37,9 @@ const ProviderForm: React.FC<ProviderFormProps> = forwardRef((props, ref) => {
|
||||
const { action, currentData, onFinish, open, clusterList } = props;
|
||||
const intl = useIntl();
|
||||
const [form] = Form.useForm();
|
||||
const profile = Form.useWatch('profile', form);
|
||||
|
||||
const { getScrollElementScrollableHeight } = useWrapperContext();
|
||||
const [activeKey, setActiveKey] = useState<string[]>([TABKeysMap.PROFILE]);
|
||||
const scrollTabsRef = useRef<any>(null);
|
||||
const showAdvanced = profile !== 'Custom' && Boolean(profile);
|
||||
|
||||
const segmentOptions = [
|
||||
{
|
||||
@@ -88,12 +85,6 @@ const ProviderForm: React.FC<ProviderFormProps> = forwardRef((props, ref) => {
|
||||
}
|
||||
}, [form, currentData, action]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!showAdvanced && activeKey?.includes(TABKeysMap.ADVANCED)) {
|
||||
setActiveKey([TABKeysMap.PROFILE]);
|
||||
}
|
||||
}, [showAdvanced, activeKey]);
|
||||
|
||||
return (
|
||||
<ScrollSpyTabs
|
||||
ref={scrollTabsRef}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
InstanceStatusMap,
|
||||
InstanceStatusMapValue
|
||||
} from '@/pages/llmodels/config';
|
||||
import { useBenchmarkTargetInstance } from '@/pages/llmodels/hooks/use-run-benchmark';
|
||||
import { useQueryModelInstancesList } from '@/pages/llmodels/services/use-query-model-instances';
|
||||
import { useQueryModelList } from '@/pages/llmodels/services/use-query-model-list';
|
||||
import { useIntl } from '@umijs/max';
|
||||
@@ -43,12 +44,15 @@ const ModelInstanceForm: React.FC = () => {
|
||||
fetchInstanceList,
|
||||
cancelRequest: cancelInstanceRequest
|
||||
} = useQueryModelInstancesList();
|
||||
const { benchmarkTargetInstance, clearBenchmarkTargetInstance } =
|
||||
useBenchmarkTargetInstance();
|
||||
|
||||
const handleOnChange = async (value: any, selectedOptions: any) => {
|
||||
form.setFieldsValue({
|
||||
model_name: value[0],
|
||||
model_id: selectedOptions[0]?.id,
|
||||
model_instance_name: value[1]
|
||||
model_instance_name: value[1],
|
||||
model_instance: value
|
||||
});
|
||||
};
|
||||
|
||||
@@ -87,43 +91,60 @@ const ModelInstanceForm: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleOnOpenChange = async (open: boolean) => {
|
||||
const initModelInstance = async () => {
|
||||
// fetch model list when dropdown is opened
|
||||
if (open && modelList.length === 0) {
|
||||
const list = await fetchModelList({ page: -1 });
|
||||
const modelOptions = list
|
||||
.filter((model: any) => model.replicas > 0)
|
||||
.map((model: any) => ({
|
||||
label: model.name,
|
||||
value: model.name,
|
||||
id: model.id,
|
||||
isLeaf: false,
|
||||
children: []
|
||||
}));
|
||||
const list = await fetchModelList({ page: -1 });
|
||||
const modelOptions = list
|
||||
.filter((model: any) => model.replicas > 0)
|
||||
.map((model: any) => ({
|
||||
label: model.name,
|
||||
value: model.name,
|
||||
id: model.id,
|
||||
isLeaf: false,
|
||||
children: []
|
||||
}));
|
||||
|
||||
if (modelOptions.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// preload instances for the first model
|
||||
const instanceList = await fetchInstanceList({ id: modelOptions[0]?.id });
|
||||
const instanceOptions = instanceList.map((instance: any) =>
|
||||
renderInstance(instance)
|
||||
);
|
||||
if (modelOptions[0]) {
|
||||
modelOptions[0].children = [...instanceOptions] as never[];
|
||||
}
|
||||
|
||||
setModelList(modelOptions);
|
||||
if (modelOptions.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// preload instances for the first model
|
||||
const instanceList = await fetchInstanceList({ id: modelOptions[0]?.id });
|
||||
const instanceOptions = instanceList.map((instance: any) =>
|
||||
renderInstance(instance)
|
||||
);
|
||||
if (modelOptions[0]) {
|
||||
modelOptions[0].children = [...instanceOptions] as never[];
|
||||
}
|
||||
|
||||
// init form value for model instance
|
||||
if (
|
||||
benchmarkTargetInstance.model_name &&
|
||||
benchmarkTargetInstance.model_instance_name
|
||||
) {
|
||||
form.setFieldsValue({
|
||||
...benchmarkTargetInstance
|
||||
});
|
||||
} else {
|
||||
handleOnChange(
|
||||
[modelOptions[0].value, instanceOptions[0]?.value],
|
||||
[modelOptions[0], instanceOptions[0]]
|
||||
);
|
||||
}
|
||||
|
||||
setModelList(modelOptions);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
initModelInstance();
|
||||
}
|
||||
if (!open) {
|
||||
cancelModelRequest();
|
||||
cancelInstanceRequest();
|
||||
clearBenchmarkTargetInstance();
|
||||
}
|
||||
}, [open]);
|
||||
}, [open, benchmarkTargetInstance]);
|
||||
|
||||
return (
|
||||
<Form.Item<FormData>
|
||||
@@ -154,7 +175,6 @@ const ModelInstanceForm: React.FC = () => {
|
||||
getPopupContainer={(triggerNode) => triggerNode.parentNode}
|
||||
optionNode={InstanceNode}
|
||||
loadData={loadInstances}
|
||||
onOpenChange={handleOnOpenChange}
|
||||
onChange={handleOnChange}
|
||||
></SealCascader>
|
||||
</Form.Item>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { FilterBar } from '@/components/page-tools';
|
||||
import { PageAction } from '@/config';
|
||||
import { TABLE_SORT_DIRECTIONS } from '@/config/settings';
|
||||
import useTableFetch from '@/hooks/use-table-fetch';
|
||||
import { useBenchmarkTargetInstance } from '@/pages/llmodels/hooks/use-run-benchmark';
|
||||
import { useQueryModelList } from '@/pages/llmodels/services/use-query-model-list';
|
||||
import { useIntl, useNavigate } from '@umijs/max';
|
||||
import { useMemoizedFn } from 'ahooks';
|
||||
@@ -76,11 +77,19 @@ const Benchmark: React.FC = () => {
|
||||
contentHeight: 320,
|
||||
clusterList
|
||||
});
|
||||
const { benchmarkTargetInstance } = useBenchmarkTargetInstance();
|
||||
|
||||
useEffect(() => {
|
||||
fetchModelList({ page: -1 });
|
||||
fetchClusterList({ page: -1 });
|
||||
fetchDatasetData();
|
||||
fetchClusterList({ page: -1 }).then(() => {
|
||||
if (benchmarkTargetInstance.model_name) {
|
||||
openBenchmarkModal(
|
||||
PageAction.CREATE,
|
||||
intl.formatMessage({ id: 'benchmark.button.add' })
|
||||
);
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
cancelClusterRequest();
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@ const useQueryDataset = () => {
|
||||
// TODO: may be fetch data from server in the future.
|
||||
|
||||
setDatasetList([...datasetOptions]);
|
||||
return datasetOptions;
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -41,7 +41,7 @@ export default function useQueryProfiles() {
|
||||
};
|
||||
}) || [];
|
||||
|
||||
setProfilesOptions([
|
||||
const options = [
|
||||
...list,
|
||||
{
|
||||
label: intl.formatMessage({ id: 'backend.custom' }),
|
||||
@@ -55,7 +55,9 @@ export default function useQueryProfiles() {
|
||||
total_requests: null
|
||||
}
|
||||
}
|
||||
]);
|
||||
];
|
||||
setProfilesOptions(options);
|
||||
return options;
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user