feat: build categorize list from object #918 (#1276)

### 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)
This commit is contained in:
balibabu
2024-06-25 19:28:24 +08:00
committed by GitHub
parent 83b91d90fe
commit fef663a59d
11 changed files with 208 additions and 69 deletions

View File

@@ -1,44 +1,13 @@
import LlmSettingItems from '@/components/llm-setting-items';
import { variableEnabledFieldMap } from '@/constants/chat';
import {
ModelVariableType,
settledModelVariableMap,
} from '@/constants/knowledge';
import { useTranslate } from '@/hooks/commonHooks';
import { Variable } from '@/interfaces/database/chat';
import { Form, Input, Switch } from 'antd';
import { useCallback, useEffect } from 'react';
import { useSetLlmSetting } from '../hooks';
import { IOperatorForm } from '../interface';
const GenerateForm = ({ onValuesChange, form }: IOperatorForm) => {
const { t } = useTranslate('flow');
const initialLlmSetting = undefined;
const handleParametersChange = useCallback(
(value: ModelVariableType) => {
const variable = settledModelVariableMap[value];
form?.setFieldsValue(variable);
},
[form],
);
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
];
return pre;
}, {});
const otherValues = settledModelVariableMap[ModelVariableType.Precise];
form?.setFieldsValue({ ...switchBoxValues, ...otherValues });
}, [form, initialLlmSetting]);
useSetLlmSetting(form);
return (
<Form
@@ -49,9 +18,7 @@ const GenerateForm = ({ onValuesChange, form }: IOperatorForm) => {
form={form}
onValuesChange={onValuesChange}
>
<LlmSettingItems
handleParametersChange={handleParametersChange}
></LlmSettingItems>
<LlmSettingItems></LlmSettingItems>
<Form.Item
name={['prompt']}
label={t('prompt', { keyPrefix: 'knowledgeConfiguration' })}