fix: default benchmark form values

This commit is contained in:
jialin
2026-02-02 14:10:46 +08:00
parent fc599a0637
commit f651ab7fd9
15 changed files with 188 additions and 53 deletions
+7 -2
View File
@@ -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 (
<>
+40 -3
View File
@@ -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}
-9
View File
@@ -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}
+49 -29
View File
@@ -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>