balibabu
commited on
Commit
·
f277af2
1
Parent(s):
04225e2
feat: build categorize list from object #918 (#1276)
Browse files### What problem does this PR solve?
feat: build categorize list from object #918
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- web/src/components/llm-select/index.tsx +18 -4
- web/src/components/llm-setting-items/index.tsx +37 -8
- web/src/pages/chat/chat-configuration-modal/model-setting.tsx +1 -15
- web/src/pages/flow/categorize-form/hooks.ts +79 -0
- web/src/pages/flow/categorize-form/index.tsx +15 -4
- web/src/pages/flow/flow-drawer/index.tsx +1 -0
- web/src/pages/flow/generate-form/index.tsx +3 -36
- web/src/pages/flow/hooks.ts +29 -0
- web/src/pages/flow/interface.ts +17 -1
- web/src/pages/flow/store.ts +4 -0
- web/src/pages/flow/utils.ts +4 -1
web/src/components/llm-select/index.tsx
CHANGED
@@ -1,16 +1,30 @@
|
|
1 |
import { Popover, Select } from 'antd';
|
2 |
import LlmSettingItems from '../llm-setting-items';
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
const content = (
|
6 |
-
<div>
|
7 |
-
<LlmSettingItems
|
|
|
|
|
8 |
</div>
|
9 |
);
|
10 |
|
11 |
return (
|
12 |
<Popover content={content} trigger="click" placement="left" arrow={false}>
|
13 |
-
<Select
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
</Popover>
|
15 |
);
|
16 |
};
|
|
|
1 |
import { Popover, Select } from 'antd';
|
2 |
import LlmSettingItems from '../llm-setting-items';
|
3 |
|
4 |
+
interface IProps {
|
5 |
+
id?: string;
|
6 |
+
value?: string;
|
7 |
+
onChange?: (value: string) => void;
|
8 |
+
}
|
9 |
+
|
10 |
+
const LLMSelect = ({ id, value, onChange }: IProps) => {
|
11 |
const content = (
|
12 |
+
<div style={{ width: 400 }}>
|
13 |
+
<LlmSettingItems
|
14 |
+
formItemLayout={{ labelCol: { span: 10 }, wrapperCol: { span: 14 } }}
|
15 |
+
></LlmSettingItems>
|
16 |
</div>
|
17 |
);
|
18 |
|
19 |
return (
|
20 |
<Popover content={content} trigger="click" placement="left" arrow={false}>
|
21 |
+
<Select
|
22 |
+
style={{ width: '100%' }}
|
23 |
+
dropdownStyle={{ display: 'none' }}
|
24 |
+
id={id}
|
25 |
+
value={value}
|
26 |
+
onChange={onChange}
|
27 |
+
/>
|
28 |
</Popover>
|
29 |
);
|
30 |
};
|
web/src/components/llm-setting-items/index.tsx
CHANGED
@@ -1,24 +1,38 @@
|
|
1 |
-
import {
|
|
|
|
|
|
|
|
|
2 |
import { Divider, Flex, Form, InputNumber, Select, Slider, Switch } from 'antd';
|
3 |
import camelCase from 'lodash/camelCase';
|
4 |
|
5 |
import { useTranslate } from '@/hooks/commonHooks';
|
6 |
import { useSelectLlmOptionsByModelType } from '@/hooks/llmHooks';
|
7 |
-
import { useMemo } from 'react';
|
8 |
import styles from './index.less';
|
9 |
|
10 |
interface IProps {
|
11 |
prefix?: string;
|
12 |
-
|
|
|
13 |
}
|
14 |
|
15 |
-
const LlmSettingItems = ({ prefix,
|
|
|
16 |
const { t } = useTranslate('chat');
|
17 |
const parameterOptions = Object.values(ModelVariableType).map((x) => ({
|
18 |
label: t(camelCase(x)),
|
19 |
value: x,
|
20 |
}));
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
const memorizedPrefix = useMemo(() => (prefix ? [prefix] : []), [prefix]);
|
23 |
|
24 |
const modelOptions = useSelectLlmOptionsByModelType();
|
@@ -29,6 +43,7 @@ const LlmSettingItems = ({ prefix, handleParametersChange }: IProps) => {
|
|
29 |
label={t('model')}
|
30 |
name="llm_id"
|
31 |
tooltip={t('modelTip')}
|
|
|
32 |
rules={[{ required: true, message: t('modelMessage') }]}
|
33 |
>
|
34 |
<Select options={modelOptions[LlmModelType.Chat]} showSearch />
|
@@ -38,6 +53,7 @@ const LlmSettingItems = ({ prefix, handleParametersChange }: IProps) => {
|
|
38 |
label={t('freedom')}
|
39 |
name="parameters"
|
40 |
tooltip={t('freedomTip')}
|
|
|
41 |
initialValue={ModelVariableType.Precise}
|
42 |
>
|
43 |
<Select<ModelVariableType>
|
@@ -45,7 +61,11 @@ const LlmSettingItems = ({ prefix, handleParametersChange }: IProps) => {
|
|
45 |
onChange={handleParametersChange}
|
46 |
/>
|
47 |
</Form.Item>
|
48 |
-
<Form.Item
|
|
|
|
|
|
|
|
|
49 |
<Flex gap={20} align="center">
|
50 |
<Form.Item
|
51 |
name={'temperatureEnabled'}
|
@@ -87,7 +107,7 @@ const LlmSettingItems = ({ prefix, handleParametersChange }: IProps) => {
|
|
87 |
</Form.Item>
|
88 |
</Flex>
|
89 |
</Form.Item>
|
90 |
-
<Form.Item label={t('topP')} tooltip={t('topPTip')}>
|
91 |
<Flex gap={20} align="center">
|
92 |
<Form.Item name={'topPEnabled'} valuePropName="checked" noStyle>
|
93 |
<Switch size="small" />
|
@@ -122,7 +142,11 @@ const LlmSettingItems = ({ prefix, handleParametersChange }: IProps) => {
|
|
122 |
</Form.Item>
|
123 |
</Flex>
|
124 |
</Form.Item>
|
125 |
-
<Form.Item
|
|
|
|
|
|
|
|
|
126 |
<Flex gap={20} align="center">
|
127 |
<Form.Item
|
128 |
name={'presencePenaltyEnabled'}
|
@@ -170,6 +194,7 @@ const LlmSettingItems = ({ prefix, handleParametersChange }: IProps) => {
|
|
170 |
<Form.Item
|
171 |
label={t('frequencyPenalty')}
|
172 |
tooltip={t('frequencyPenaltyTip')}
|
|
|
173 |
>
|
174 |
<Flex gap={20} align="center">
|
175 |
<Form.Item
|
@@ -215,7 +240,11 @@ const LlmSettingItems = ({ prefix, handleParametersChange }: IProps) => {
|
|
215 |
</Form.Item>
|
216 |
</Flex>
|
217 |
</Form.Item>
|
218 |
-
<Form.Item
|
|
|
|
|
|
|
|
|
219 |
<Flex gap={20} align="center">
|
220 |
<Form.Item name={'maxTokensEnabled'} valuePropName="checked" noStyle>
|
221 |
<Switch size="small" />
|
|
|
1 |
+
import {
|
2 |
+
LlmModelType,
|
3 |
+
ModelVariableType,
|
4 |
+
settledModelVariableMap,
|
5 |
+
} from '@/constants/knowledge';
|
6 |
import { Divider, Flex, Form, InputNumber, Select, Slider, Switch } from 'antd';
|
7 |
import camelCase from 'lodash/camelCase';
|
8 |
|
9 |
import { useTranslate } from '@/hooks/commonHooks';
|
10 |
import { useSelectLlmOptionsByModelType } from '@/hooks/llmHooks';
|
11 |
+
import { useCallback, useMemo } from 'react';
|
12 |
import styles from './index.less';
|
13 |
|
14 |
interface IProps {
|
15 |
prefix?: string;
|
16 |
+
formItemLayout?: any;
|
17 |
+
handleParametersChange?(value: ModelVariableType): void;
|
18 |
}
|
19 |
|
20 |
+
const LlmSettingItems = ({ prefix, formItemLayout = {} }: IProps) => {
|
21 |
+
const form = Form.useFormInstance();
|
22 |
const { t } = useTranslate('chat');
|
23 |
const parameterOptions = Object.values(ModelVariableType).map((x) => ({
|
24 |
label: t(camelCase(x)),
|
25 |
value: x,
|
26 |
}));
|
27 |
|
28 |
+
const handleParametersChange = useCallback(
|
29 |
+
(value: ModelVariableType) => {
|
30 |
+
const variable = settledModelVariableMap[value];
|
31 |
+
form?.setFieldsValue(variable);
|
32 |
+
},
|
33 |
+
[form],
|
34 |
+
);
|
35 |
+
|
36 |
const memorizedPrefix = useMemo(() => (prefix ? [prefix] : []), [prefix]);
|
37 |
|
38 |
const modelOptions = useSelectLlmOptionsByModelType();
|
|
|
43 |
label={t('model')}
|
44 |
name="llm_id"
|
45 |
tooltip={t('modelTip')}
|
46 |
+
{...formItemLayout}
|
47 |
rules={[{ required: true, message: t('modelMessage') }]}
|
48 |
>
|
49 |
<Select options={modelOptions[LlmModelType.Chat]} showSearch />
|
|
|
53 |
label={t('freedom')}
|
54 |
name="parameters"
|
55 |
tooltip={t('freedomTip')}
|
56 |
+
{...formItemLayout}
|
57 |
initialValue={ModelVariableType.Precise}
|
58 |
>
|
59 |
<Select<ModelVariableType>
|
|
|
61 |
onChange={handleParametersChange}
|
62 |
/>
|
63 |
</Form.Item>
|
64 |
+
<Form.Item
|
65 |
+
label={t('temperature')}
|
66 |
+
tooltip={t('temperatureTip')}
|
67 |
+
{...formItemLayout}
|
68 |
+
>
|
69 |
<Flex gap={20} align="center">
|
70 |
<Form.Item
|
71 |
name={'temperatureEnabled'}
|
|
|
107 |
</Form.Item>
|
108 |
</Flex>
|
109 |
</Form.Item>
|
110 |
+
<Form.Item label={t('topP')} tooltip={t('topPTip')} {...formItemLayout}>
|
111 |
<Flex gap={20} align="center">
|
112 |
<Form.Item name={'topPEnabled'} valuePropName="checked" noStyle>
|
113 |
<Switch size="small" />
|
|
|
142 |
</Form.Item>
|
143 |
</Flex>
|
144 |
</Form.Item>
|
145 |
+
<Form.Item
|
146 |
+
label={t('presencePenalty')}
|
147 |
+
tooltip={t('presencePenaltyTip')}
|
148 |
+
{...formItemLayout}
|
149 |
+
>
|
150 |
<Flex gap={20} align="center">
|
151 |
<Form.Item
|
152 |
name={'presencePenaltyEnabled'}
|
|
|
194 |
<Form.Item
|
195 |
label={t('frequencyPenalty')}
|
196 |
tooltip={t('frequencyPenaltyTip')}
|
197 |
+
{...formItemLayout}
|
198 |
>
|
199 |
<Flex gap={20} align="center">
|
200 |
<Form.Item
|
|
|
240 |
</Form.Item>
|
241 |
</Flex>
|
242 |
</Form.Item>
|
243 |
+
<Form.Item
|
244 |
+
label={t('maxTokens')}
|
245 |
+
tooltip={t('maxTokensTip')}
|
246 |
+
{...formItemLayout}
|
247 |
+
>
|
248 |
<Flex gap={20} align="center">
|
249 |
<Form.Item name={'maxTokensEnabled'} valuePropName="checked" noStyle>
|
250 |
<Switch size="small" />
|
web/src/pages/chat/chat-configuration-modal/model-setting.tsx
CHANGED
@@ -1,7 +1,3 @@
|
|
1 |
-
import {
|
2 |
-
ModelVariableType,
|
3 |
-
settledModelVariableMap,
|
4 |
-
} from '@/constants/knowledge';
|
5 |
import classNames from 'classnames';
|
6 |
import { useEffect } from 'react';
|
7 |
import { ISegmentedContentProps } from '../interface';
|
@@ -20,11 +16,6 @@ const ModelSetting = ({
|
|
20 |
initialLlmSetting?: Variable;
|
21 |
visible?: boolean;
|
22 |
}) => {
|
23 |
-
const handleParametersChange = (value: ModelVariableType) => {
|
24 |
-
const variable = settledModelVariableMap[value];
|
25 |
-
form.setFieldsValue({ llm_setting: variable });
|
26 |
-
};
|
27 |
-
|
28 |
useEffect(() => {
|
29 |
if (visible) {
|
30 |
const values = Object.keys(variableEnabledFieldMap).reduce<
|
@@ -50,12 +41,7 @@ const ModelSetting = ({
|
|
50 |
[styles.segmentedHidden]: !show,
|
51 |
})}
|
52 |
>
|
53 |
-
{visible &&
|
54 |
-
<LlmSettingItems
|
55 |
-
prefix="llm_setting"
|
56 |
-
handleParametersChange={handleParametersChange}
|
57 |
-
></LlmSettingItems>
|
58 |
-
)}
|
59 |
{/* <Form.Item
|
60 |
label={t('model')}
|
61 |
name="llm_id"
|
|
|
|
|
|
|
|
|
|
|
1 |
import classNames from 'classnames';
|
2 |
import { useEffect } from 'react';
|
3 |
import { ISegmentedContentProps } from '../interface';
|
|
|
16 |
initialLlmSetting?: Variable;
|
17 |
visible?: boolean;
|
18 |
}) => {
|
|
|
|
|
|
|
|
|
|
|
19 |
useEffect(() => {
|
20 |
if (visible) {
|
21 |
const values = Object.keys(variableEnabledFieldMap).reduce<
|
|
|
41 |
[styles.segmentedHidden]: !show,
|
42 |
})}
|
43 |
>
|
44 |
+
{visible && <LlmSettingItems prefix="llm_setting"></LlmSettingItems>}
|
|
|
|
|
|
|
|
|
|
|
45 |
{/* <Form.Item
|
46 |
label={t('model')}
|
47 |
name="llm_id"
|
web/src/pages/flow/categorize-form/hooks.ts
CHANGED
@@ -1,4 +1,12 @@
|
|
|
|
|
|
|
|
1 |
import { Operator } from '../constant';
|
|
|
|
|
|
|
|
|
|
|
2 |
import useGraphStore from '../store';
|
3 |
|
4 |
// exclude some nodes downstream of the classification node
|
@@ -11,3 +19,74 @@ export const useBuildCategorizeToOptions = () => {
|
|
11 |
.filter((x) => excludedNodes.every((y) => y !== x.data.label))
|
12 |
.map((x) => ({ label: x.id, value: x.id }));
|
13 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import get from 'lodash/get';
|
2 |
+
import omit from 'lodash/omit';
|
3 |
+
import { useCallback, useEffect } from 'react';
|
4 |
import { Operator } from '../constant';
|
5 |
+
import {
|
6 |
+
ICategorizeItem,
|
7 |
+
ICategorizeItemResult,
|
8 |
+
IOperatorForm,
|
9 |
+
} from '../interface';
|
10 |
import useGraphStore from '../store';
|
11 |
|
12 |
// exclude some nodes downstream of the classification node
|
|
|
19 |
.filter((x) => excludedNodes.every((y) => y !== x.data.label))
|
20 |
.map((x) => ({ label: x.id, value: x.id }));
|
21 |
};
|
22 |
+
|
23 |
+
/**
|
24 |
+
* convert the following object into a list
|
25 |
+
*
|
26 |
+
* {
|
27 |
+
"product_related": {
|
28 |
+
"description": "The question is about product usage, appearance and how it works.",
|
29 |
+
"examples": "Why it always beaming?\nHow to install it onto the wall?\nIt leaks, what to do?",
|
30 |
+
"to": "generate:0"
|
31 |
+
}
|
32 |
+
}
|
33 |
+
*/
|
34 |
+
const buildCategorizeListFromObject = (
|
35 |
+
categorizeItem: ICategorizeItemResult,
|
36 |
+
) => {
|
37 |
+
return Object.keys(categorizeItem).reduce<Array<ICategorizeItem>>(
|
38 |
+
(pre, cur) => {
|
39 |
+
pre.push({ name: cur, ...categorizeItem[cur] });
|
40 |
+
return pre;
|
41 |
+
},
|
42 |
+
[],
|
43 |
+
);
|
44 |
+
};
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Convert the list in the following form into an object
|
48 |
+
* {
|
49 |
+
"items": [
|
50 |
+
{
|
51 |
+
"name": "Categorize 1",
|
52 |
+
"description": "111",
|
53 |
+
"examples": "ddd",
|
54 |
+
"to": "Retrieval:LazyEelsStick"
|
55 |
+
}
|
56 |
+
]
|
57 |
+
}
|
58 |
+
*/
|
59 |
+
const buildCategorizeObjectFromList = (list: Array<ICategorizeItem>) => {
|
60 |
+
return list.reduce<ICategorizeItemResult>((pre, cur) => {
|
61 |
+
if (cur?.name) {
|
62 |
+
pre[cur.name] = omit(cur, 'name');
|
63 |
+
}
|
64 |
+
return pre;
|
65 |
+
}, {});
|
66 |
+
};
|
67 |
+
|
68 |
+
export const useHandleFormValuesChange = ({
|
69 |
+
onValuesChange,
|
70 |
+
form,
|
71 |
+
node,
|
72 |
+
}: IOperatorForm) => {
|
73 |
+
const handleValuesChange = useCallback(
|
74 |
+
(changedValues: any, values: any) => {
|
75 |
+
onValuesChange?.(changedValues, {
|
76 |
+
...omit(values, 'items'),
|
77 |
+
category_description: buildCategorizeObjectFromList(values.items),
|
78 |
+
});
|
79 |
+
},
|
80 |
+
[onValuesChange],
|
81 |
+
);
|
82 |
+
|
83 |
+
useEffect(() => {
|
84 |
+
form?.setFieldsValue({
|
85 |
+
items: buildCategorizeListFromObject(
|
86 |
+
get(node, 'data.form.category_description', {}),
|
87 |
+
),
|
88 |
+
});
|
89 |
+
}, [form, node]);
|
90 |
+
|
91 |
+
return { handleValuesChange };
|
92 |
+
};
|
web/src/pages/flow/categorize-form/index.tsx
CHANGED
@@ -1,11 +1,19 @@
|
|
1 |
import LLMSelect from '@/components/llm-select';
|
2 |
import { useTranslate } from '@/hooks/commonHooks';
|
3 |
import { Form } from 'antd';
|
|
|
4 |
import { IOperatorForm } from '../interface';
|
5 |
import DynamicCategorize from './dynamic-categorize';
|
|
|
6 |
|
7 |
-
const CategorizeForm = ({ form, onValuesChange }: IOperatorForm) => {
|
8 |
const { t } = useTranslate('flow');
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
return (
|
11 |
<Form
|
@@ -14,11 +22,14 @@ const CategorizeForm = ({ form, onValuesChange }: IOperatorForm) => {
|
|
14 |
wrapperCol={{ span: 15 }}
|
15 |
autoComplete="off"
|
16 |
form={form}
|
17 |
-
onValuesChange={
|
18 |
initialValues={{ items: [{}] }}
|
19 |
-
// layout={'vertical'}
|
20 |
>
|
21 |
-
<Form.Item
|
|
|
|
|
|
|
|
|
22 |
<LLMSelect></LLMSelect>
|
23 |
</Form.Item>
|
24 |
<DynamicCategorize></DynamicCategorize>
|
|
|
1 |
import LLMSelect from '@/components/llm-select';
|
2 |
import { useTranslate } from '@/hooks/commonHooks';
|
3 |
import { Form } from 'antd';
|
4 |
+
import { useSetLlmSetting } from '../hooks';
|
5 |
import { IOperatorForm } from '../interface';
|
6 |
import DynamicCategorize from './dynamic-categorize';
|
7 |
+
import { useHandleFormValuesChange } from './hooks';
|
8 |
|
9 |
+
const CategorizeForm = ({ form, onValuesChange, node }: IOperatorForm) => {
|
10 |
const { t } = useTranslate('flow');
|
11 |
+
const { handleValuesChange } = useHandleFormValuesChange({
|
12 |
+
form,
|
13 |
+
node,
|
14 |
+
onValuesChange,
|
15 |
+
});
|
16 |
+
useSetLlmSetting(form);
|
17 |
|
18 |
return (
|
19 |
<Form
|
|
|
22 |
wrapperCol={{ span: 15 }}
|
23 |
autoComplete="off"
|
24 |
form={form}
|
25 |
+
onValuesChange={handleValuesChange}
|
26 |
initialValues={{ items: [{}] }}
|
|
|
27 |
>
|
28 |
+
<Form.Item
|
29 |
+
name={'llm_id'}
|
30 |
+
label={t('model', { keyPrefix: 'chat' })}
|
31 |
+
tooltip={t('modelTip', { keyPrefix: 'chat' })}
|
32 |
+
>
|
33 |
<LLMSelect></LLMSelect>
|
34 |
</Form.Item>
|
35 |
<DynamicCategorize></DynamicCategorize>
|
web/src/pages/flow/flow-drawer/index.tsx
CHANGED
@@ -53,6 +53,7 @@ const FlowDrawer = ({
|
|
53 |
<OperatorForm
|
54 |
onValuesChange={handleValuesChange}
|
55 |
form={form}
|
|
|
56 |
></OperatorForm>
|
57 |
)}
|
58 |
</Drawer>
|
|
|
53 |
<OperatorForm
|
54 |
onValuesChange={handleValuesChange}
|
55 |
form={form}
|
56 |
+
node={node}
|
57 |
></OperatorForm>
|
58 |
)}
|
59 |
</Drawer>
|
web/src/pages/flow/generate-form/index.tsx
CHANGED
@@ -1,44 +1,13 @@
|
|
1 |
import LlmSettingItems from '@/components/llm-setting-items';
|
2 |
-
import { variableEnabledFieldMap } from '@/constants/chat';
|
3 |
-
import {
|
4 |
-
ModelVariableType,
|
5 |
-
settledModelVariableMap,
|
6 |
-
} from '@/constants/knowledge';
|
7 |
import { useTranslate } from '@/hooks/commonHooks';
|
8 |
-
import { Variable } from '@/interfaces/database/chat';
|
9 |
import { Form, Input, Switch } from 'antd';
|
10 |
-
import {
|
11 |
import { IOperatorForm } from '../interface';
|
12 |
|
13 |
const GenerateForm = ({ onValuesChange, form }: IOperatorForm) => {
|
14 |
const { t } = useTranslate('flow');
|
15 |
-
const initialLlmSetting = undefined;
|
16 |
|
17 |
-
|
18 |
-
(value: ModelVariableType) => {
|
19 |
-
const variable = settledModelVariableMap[value];
|
20 |
-
form?.setFieldsValue(variable);
|
21 |
-
},
|
22 |
-
[form],
|
23 |
-
);
|
24 |
-
|
25 |
-
useEffect(() => {
|
26 |
-
const switchBoxValues = Object.keys(variableEnabledFieldMap).reduce<
|
27 |
-
Record<string, boolean>
|
28 |
-
>((pre, field) => {
|
29 |
-
pre[field] =
|
30 |
-
initialLlmSetting === undefined
|
31 |
-
? true
|
32 |
-
: !!initialLlmSetting[
|
33 |
-
variableEnabledFieldMap[
|
34 |
-
field as keyof typeof variableEnabledFieldMap
|
35 |
-
] as keyof Variable
|
36 |
-
];
|
37 |
-
return pre;
|
38 |
-
}, {});
|
39 |
-
const otherValues = settledModelVariableMap[ModelVariableType.Precise];
|
40 |
-
form?.setFieldsValue({ ...switchBoxValues, ...otherValues });
|
41 |
-
}, [form, initialLlmSetting]);
|
42 |
|
43 |
return (
|
44 |
<Form
|
@@ -49,9 +18,7 @@ const GenerateForm = ({ onValuesChange, form }: IOperatorForm) => {
|
|
49 |
form={form}
|
50 |
onValuesChange={onValuesChange}
|
51 |
>
|
52 |
-
<LlmSettingItems
|
53 |
-
handleParametersChange={handleParametersChange}
|
54 |
-
></LlmSettingItems>
|
55 |
<Form.Item
|
56 |
name={['prompt']}
|
57 |
label={t('prompt', { keyPrefix: 'knowledgeConfiguration' })}
|
|
|
1 |
import LlmSettingItems from '@/components/llm-setting-items';
|
|
|
|
|
|
|
|
|
|
|
2 |
import { useTranslate } from '@/hooks/commonHooks';
|
|
|
3 |
import { Form, Input, Switch } from 'antd';
|
4 |
+
import { useSetLlmSetting } from '../hooks';
|
5 |
import { IOperatorForm } from '../interface';
|
6 |
|
7 |
const GenerateForm = ({ onValuesChange, form }: IOperatorForm) => {
|
8 |
const { t } = useTranslate('flow');
|
|
|
9 |
|
10 |
+
useSetLlmSetting(form);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
return (
|
13 |
<Form
|
|
|
18 |
form={form}
|
19 |
onValuesChange={onValuesChange}
|
20 |
>
|
21 |
+
<LlmSettingItems></LlmSettingItems>
|
|
|
|
|
22 |
<Form.Item
|
23 |
name={['prompt']}
|
24 |
label={t('prompt', { keyPrefix: 'knowledgeConfiguration' })}
|
web/src/pages/flow/hooks.ts
CHANGED
@@ -15,7 +15,14 @@ import React, {
|
|
15 |
} from 'react';
|
16 |
import { Node, Position, ReactFlowInstance } from 'reactflow';
|
17 |
// import { shallow } from 'zustand/shallow';
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
import { useDebounceEffect } from 'ahooks';
|
|
|
19 |
import { humanId } from 'human-id';
|
20 |
import { useParams } from 'umi';
|
21 |
import { Operator } from './constant';
|
@@ -218,3 +225,25 @@ export const useFetchDataOnMount = () => {
|
|
218 |
export const useFlowIsFetching = () => {
|
219 |
return useIsFetching({ queryKey: ['flowDetail'] }) > 0;
|
220 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
} from 'react';
|
16 |
import { Node, Position, ReactFlowInstance } from 'reactflow';
|
17 |
// import { shallow } from 'zustand/shallow';
|
18 |
+
import { variableEnabledFieldMap } from '@/constants/chat';
|
19 |
+
import {
|
20 |
+
ModelVariableType,
|
21 |
+
settledModelVariableMap,
|
22 |
+
} from '@/constants/knowledge';
|
23 |
+
import { Variable } from '@/interfaces/database/chat';
|
24 |
import { useDebounceEffect } from 'ahooks';
|
25 |
+
import { FormInstance } from 'antd';
|
26 |
import { humanId } from 'human-id';
|
27 |
import { useParams } from 'umi';
|
28 |
import { Operator } from './constant';
|
|
|
225 |
export const useFlowIsFetching = () => {
|
226 |
return useIsFetching({ queryKey: ['flowDetail'] }) > 0;
|
227 |
};
|
228 |
+
|
229 |
+
export const useSetLlmSetting = (form?: FormInstance) => {
|
230 |
+
const initialLlmSetting = undefined;
|
231 |
+
|
232 |
+
useEffect(() => {
|
233 |
+
const switchBoxValues = Object.keys(variableEnabledFieldMap).reduce<
|
234 |
+
Record<string, boolean>
|
235 |
+
>((pre, field) => {
|
236 |
+
pre[field] =
|
237 |
+
initialLlmSetting === undefined
|
238 |
+
? true
|
239 |
+
: !!initialLlmSetting[
|
240 |
+
variableEnabledFieldMap[
|
241 |
+
field as keyof typeof variableEnabledFieldMap
|
242 |
+
] as keyof Variable
|
243 |
+
];
|
244 |
+
return pre;
|
245 |
+
}, {});
|
246 |
+
const otherValues = settledModelVariableMap[ModelVariableType.Precise];
|
247 |
+
form?.setFieldsValue({ ...switchBoxValues, ...otherValues });
|
248 |
+
}, [form, initialLlmSetting]);
|
249 |
+
};
|
web/src/pages/flow/interface.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import { FormInstance } from 'antd';
|
|
|
2 |
|
3 |
export interface DSLComponentList {
|
4 |
id: string;
|
@@ -8,6 +9,7 @@ export interface DSLComponentList {
|
|
8 |
export interface IOperatorForm {
|
9 |
onValuesChange?(changedValues: any, values: any): void;
|
10 |
form?: FormInstance;
|
|
|
11 |
}
|
12 |
|
13 |
export interface IBeginForm {
|
@@ -35,9 +37,23 @@ export interface IGenerateForm {
|
|
35 |
llm_id: string;
|
36 |
parameters: { key: string; component_id: string };
|
37 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
export type NodeData = {
|
40 |
label: string;
|
41 |
color: string;
|
42 |
-
form: IBeginForm | IRetrievalForm | IGenerateForm;
|
43 |
};
|
|
|
1 |
import { FormInstance } from 'antd';
|
2 |
+
import { Node } from 'reactflow';
|
3 |
|
4 |
export interface DSLComponentList {
|
5 |
id: string;
|
|
|
9 |
export interface IOperatorForm {
|
10 |
onValuesChange?(changedValues: any, values: any): void;
|
11 |
form?: FormInstance;
|
12 |
+
node?: Node<NodeData>;
|
13 |
}
|
14 |
|
15 |
export interface IBeginForm {
|
|
|
37 |
llm_id: string;
|
38 |
parameters: { key: string; component_id: string };
|
39 |
}
|
40 |
+
export interface ICategorizeItem {
|
41 |
+
name: string;
|
42 |
+
description?: string;
|
43 |
+
examples?: string;
|
44 |
+
to?: string;
|
45 |
+
}
|
46 |
+
|
47 |
+
export type ICategorizeItemResult = Record<
|
48 |
+
string,
|
49 |
+
Omit<ICategorizeItem, 'name'>
|
50 |
+
>;
|
51 |
+
export interface ICategorizeForm extends IGenerateForm {
|
52 |
+
category_description: ICategorizeItemResult;
|
53 |
+
}
|
54 |
|
55 |
export type NodeData = {
|
56 |
label: string;
|
57 |
color: string;
|
58 |
+
form: IBeginForm | IRetrievalForm | IGenerateForm | ICategorizeForm;
|
59 |
};
|
web/src/pages/flow/store.ts
CHANGED
@@ -39,6 +39,7 @@ export type RFState = {
|
|
39 |
deleteEdgeById: (id: string) => void;
|
40 |
deleteNodeById: (id: string) => void;
|
41 |
findNodeByName: (operatorName: Operator) => Node | undefined;
|
|
|
42 |
};
|
43 |
|
44 |
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
@@ -125,6 +126,9 @@ const useGraphStore = create<RFState>()(
|
|
125 |
findNodeByName: (name: Operator) => {
|
126 |
return get().nodes.find((x) => x.data.label === name);
|
127 |
},
|
|
|
|
|
|
|
128 |
updateNodeForm: (nodeId: string, values: any) => {
|
129 |
set({
|
130 |
nodes: get().nodes.map((node) => {
|
|
|
39 |
deleteEdgeById: (id: string) => void;
|
40 |
deleteNodeById: (id: string) => void;
|
41 |
findNodeByName: (operatorName: Operator) => Node | undefined;
|
42 |
+
findNodeById: (id: string) => Node | undefined;
|
43 |
};
|
44 |
|
45 |
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
|
|
126 |
findNodeByName: (name: Operator) => {
|
127 |
return get().nodes.find((x) => x.data.label === name);
|
128 |
},
|
129 |
+
findNodeById: (id: string) => {
|
130 |
+
return get().nodes.find((x) => x.id === id);
|
131 |
+
},
|
132 |
updateNodeForm: (nodeId: string, values: any) => {
|
133 |
set({
|
134 |
nodes: get().nodes.map((node) => {
|
web/src/pages/flow/utils.ts
CHANGED
@@ -114,7 +114,10 @@ const buildComponentDownstreamOrUpstream = (
|
|
114 |
|
115 |
const removeUselessDataInTheOperator = curry(
|
116 |
(operatorName: string, params: Record<string, unknown>) => {
|
117 |
-
if (
|
|
|
|
|
|
|
118 |
return removeUselessFieldsFromValues(params, '');
|
119 |
}
|
120 |
return params;
|
|
|
114 |
|
115 |
const removeUselessDataInTheOperator = curry(
|
116 |
(operatorName: string, params: Record<string, unknown>) => {
|
117 |
+
if (
|
118 |
+
operatorName === Operator.Generate ||
|
119 |
+
operatorName === Operator.Categorize
|
120 |
+
) {
|
121 |
return removeUselessFieldsFromValues(params, '');
|
122 |
}
|
123 |
return params;
|