Feat: remove useSetLlmSetting from GenerateForm #3591 (#3592)

### What problem does this PR solve?

Feat: remove useSetLlmSetting from GenerateForm #3591

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
balibabu
2024-11-22 16:31:44 +08:00
committed by GitHub
parent cc219ff648
commit 06b9256972
8 changed files with 22 additions and 30 deletions

View File

@ -23,7 +23,7 @@ import { FormInstance, message } from 'antd';
import { DefaultOptionType } from 'antd/es/select';
import dayjs from 'dayjs';
import { humanId } from 'human-id';
import { get, lowerFirst } from 'lodash';
import { get, isEmpty, lowerFirst, pick } from 'lodash';
import trim from 'lodash/trim';
import { useTranslation } from 'react-i18next';
import { useParams } from 'umi';
@ -349,24 +349,31 @@ export const useFlowIsFetching = () => {
return useIsFetching({ queryKey: ['flowDetail'] }) > 0;
};
export const useSetLlmSetting = (form?: FormInstance) => {
const initialLlmSetting = undefined;
export const useSetLlmSetting = (
form?: FormInstance,
formData?: Record<string, any>,
) => {
const initialLlmSetting = pick(
formData,
Object.values(variableEnabledFieldMap),
);
useEffect(() => {
const switchBoxValues = Object.keys(variableEnabledFieldMap).reduce<
Record<string, boolean>
>((pre, field) => {
pre[field] =
initialLlmSetting === undefined
? true
: !!initialLlmSetting[
variableEnabledFieldMap[
field as keyof typeof variableEnabledFieldMap
] as keyof Variable
];
pre[field] = isEmpty(initialLlmSetting)
? true
: !!initialLlmSetting[
variableEnabledFieldMap[
field as keyof typeof variableEnabledFieldMap
] as keyof Variable
];
return pre;
}, {});
const otherValues = settledModelVariableMap[ModelVariableType.Precise];
let otherValues = settledModelVariableMap[ModelVariableType.Precise];
if (!isEmpty(initialLlmSetting)) {
otherValues = initialLlmSetting;
}
form?.setFieldsValue({
...switchBoxValues,
...otherValues,