Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

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

balibabu06b925697281
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index 58e4908321..a634842997 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -594,8 +594,8 @@ The above is the content you need to summarize.`,
updateDate: 'Update Date',
role: 'Role',
invite: 'Invite',
- agree: 'Agree',
- refuse: 'Refuse',
+ agree: 'Accept',
+ refuse: 'Decline',
teamMembers: 'Team Members',
joinedTeams: 'Joined Teams',
},
diff --git a/web/src/pages/flow/form/categorize-form/index.tsx b/web/src/pages/flow/form/categorize-form/index.tsx
index b9095057ab..00debf47f1 100644
--- a/web/src/pages/flow/form/categorize-form/index.tsx
+++ b/web/src/pages/flow/form/categorize-form/index.tsx
@@ -2,7 +2,6 @@ import LLMSelect from '@/components/llm-select';
import MessageHistoryWindowSizeItem from '@/components/message-history-window-size-item';
import { useTranslate } from '@/hooks/common-hooks';
import { Form } from 'antd';
-import { useSetLlmSetting } from '../../hooks';
import { IOperatorForm } from '../../interface';
import DynamicInputVariable from '../components/dynamic-input-variable';
import DynamicCategorize from './dynamic-categorize';
@@ -15,7 +14,6 @@ const CategorizeForm = ({ form, onValuesChange, node }: IOperatorForm) => {
nodeId: node?.id,
onValuesChange,
});
- useSetLlmSetting(form);
return (
<Form
diff --git a/web/src/pages/flow/form/generate-form/index.tsx b/web/src/pages/flow/form/generate-form/index.tsx
index 84676e83b5..0b5a77b1a5 100644
--- a/web/src/pages/flow/form/generate-form/index.tsx
+++ b/web/src/pages/flow/form/generate-form/index.tsx
@@ -2,15 +2,12 @@ import LLMSelect from '@/components/llm-select';
import MessageHistoryWindowSizeItem from '@/components/message-history-window-size-item';
import { useTranslate } from '@/hooks/common-hooks';
import { Form, Input, Switch } from 'antd';
-import { useSetLlmSetting } from '../../hooks';
import { IOperatorForm } from '../../interface';
import DynamicParameters from './dynamic-parameters';
const GenerateForm = ({ onValuesChange, form, node }: IOperatorForm) => {
const { t } = useTranslate('flow');
- useSetLlmSetting(form);
-
return (
<Form
name="basic"
diff --git a/web/src/pages/flow/form/invoke-form/index.tsx b/web/src/pages/flow/form/invoke-form/index.tsx
index 147499333f..926ca8f2ab 100644
--- a/web/src/pages/flow/form/invoke-form/index.tsx
+++ b/web/src/pages/flow/form/invoke-form/index.tsx
@@ -1,7 +1,6 @@
import Editor from '@monaco-editor/react';
import { Form, Input, InputNumber, Select, Space, Switch } from 'antd';
import { useTranslation } from 'react-i18next';
-import { useSetLlmSetting } from '../../hooks';
import { IOperatorForm } from '../../interface';
import DynamicVariablesForm from './dynamic-variables';
@@ -33,8 +32,6 @@ const TimeoutInput = ({ value, onChange }: TimeoutInputProps) => {
const InvokeForm = ({ onValuesChange, form, node }: IOperatorForm) => {
const { t } = useTranslation();
- useSetLlmSetting(form);
-
return (
<>
<Form
diff --git a/web/src/pages/flow/form/keyword-extract-form/index.tsx b/web/src/pages/flow/form/keyword-extract-form/index.tsx
index f4265b5fc5..fa969724b9 100644
--- a/web/src/pages/flow/form/keyword-extract-form/index.tsx
+++ b/web/src/pages/flow/form/keyword-extract-form/index.tsx
@@ -2,15 +2,12 @@ import LLMSelect from '@/components/llm-select';
import TopNItem from '@/components/top-n-item';
import { useTranslate } from '@/hooks/common-hooks';
import { Form } from 'antd';
-import { useSetLlmSetting } from '../../hooks';
import { IOperatorForm } from '../../interface';
import DynamicInputVariable from '../components/dynamic-input-variable';
const KeywordExtractForm = ({ onValuesChange, form, node }: IOperatorForm) => {
const { t } = useTranslate('flow');
- useSetLlmSetting(form);
-
return (
<Form
name="basic"
diff --git a/web/src/pages/flow/form/relevant-form/index.tsx b/web/src/pages/flow/form/relevant-form/index.tsx
index 92ae5498c6..e2366f6f05 100644
--- a/web/src/pages/flow/form/relevant-form/index.tsx
+++ b/web/src/pages/flow/form/relevant-form/index.tsx
@@ -3,13 +3,11 @@ import { useTranslate } from '@/hooks/common-hooks';
import { Form, Select } from 'antd';
import { Operator } from '../../constant';
import { useBuildFormSelectOptions } from '../../form-hooks';
-import { useSetLlmSetting } from '../../hooks';
import { IOperatorForm } from '../../interface';
import { useWatchConnectionChanges } from './hooks';
const RelevantForm = ({ onValuesChange, form, node }: IOperatorForm) => {
const { t } = useTranslate('flow');
- useSetLlmSetting(form);
const buildRelevantOptions = useBuildFormSelectOptions(
Operator.Relevant,
node?.id,
diff --git a/web/src/pages/flow/form/rewrite-question-form/index.tsx b/web/src/pages/flow/form/rewrite-question-form/index.tsx
index cbf5f27f0b..1aa9164158 100644
--- a/web/src/pages/flow/form/rewrite-question-form/index.tsx
+++ b/web/src/pages/flow/form/rewrite-question-form/index.tsx
@@ -1,12 +1,10 @@
import LLMSelect from '@/components/llm-select';
import { useTranslate } from '@/hooks/common-hooks';
import { Form, InputNumber } from 'antd';
-import { useSetLlmSetting } from '../../hooks';
import { IOperatorForm } from '../../interface';
const RewriteQuestionForm = ({ onValuesChange, form }: IOperatorForm) => {
const { t } = useTranslate('chat');
- useSetLlmSetting(form);
return (
<Form
diff --git a/web/src/pages/flow/hooks.tsx b/web/src/pages/flow/hooks.tsx
index dd4b15c56b..e33bc3b700 100644
--- a/web/src/pages/flow/hooks.tsx
+++ b/web/src/pages/flow/hooks.tsx
@@ -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,