Feat: Add VariablePickerMenuPlugin to select variables in the prompt text box by menu #4764 (#4765)

### What problem does this PR solve?

Feat: Add VariablePickerMenuPlugin to select variables in the prompt
text box by menu #4764

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-02-08 18:09:13 +08:00
committed by GitHub
parent f64ae9dc33
commit bfcc2abe47
19 changed files with 1058 additions and 126 deletions

View File

@ -1,38 +1,10 @@
import get from 'lodash/get';
import omit from 'lodash/omit';
import { useCallback, useEffect } from 'react';
import {
ICategorizeItem,
ICategorizeItemResult,
IOperatorForm,
} from '../../interface';
import useGraphStore from '../../store';
/**
* convert the following object into a list
*
* {
"product_related": {
"description": "The question is about product usage, appearance and how it works.",
"examples": "Why it always beaming?\nHow to install it onto the wall?\nIt leaks, what to do?",
"to": "generate:0"
}
}
*/
const buildCategorizeListFromObject = (
categorizeItem: ICategorizeItemResult,
) => {
// Categorize's to field has two data sources, with edges as the data source.
// Changes in the edge or to field need to be synchronized to the form field.
return Object.keys(categorizeItem)
.reduce<Array<ICategorizeItem>>((pre, cur) => {
// synchronize edge data to the to field
pre.push({ name: cur, ...categorizeItem[cur] });
return pre;
}, [])
.sort((a, b) => a.index - b.index);
};
} from '@/interfaces/database/flow';
import omit from 'lodash/omit';
import { useCallback } from 'react';
import { IOperatorForm } from '../../interface';
/**
* Convert the list in the following form into an object
@ -58,12 +30,7 @@ const buildCategorizeObjectFromList = (list: Array<ICategorizeItem>) => {
export const useHandleFormValuesChange = ({
onValuesChange,
form,
nodeId,
}: IOperatorForm) => {
const getNode = useGraphStore((state) => state.getNode);
const node = getNode(nodeId);
const handleValuesChange = useCallback(
(changedValues: any, values: any) => {
onValuesChange?.(changedValues, {
@ -74,14 +41,5 @@ export const useHandleFormValuesChange = ({
[onValuesChange],
);
useEffect(() => {
const items = buildCategorizeListFromObject(
get(node, 'data.form.category_description', {}),
);
form?.setFieldsValue({
items,
});
}, [form, node]);
return { handleValuesChange };
};

View File

@ -1,11 +1,11 @@
import LLMSelect from '@/components/llm-select';
import MessageHistoryWindowSizeItem from '@/components/message-history-window-size-item';
import { PromptEditor } from '@/components/prompt-editor';
import { useTranslate } from '@/hooks/common-hooks';
import { Form, Input, Switch } from 'antd';
import { Form, Switch } from 'antd';
import { IOperatorForm } from '../../interface';
import DynamicParameters from './dynamic-parameters';
const GenerateForm = ({ onValuesChange, form, node }: IOperatorForm) => {
const GenerateForm = ({ onValuesChange, form }: IOperatorForm) => {
const { t } = useTranslate('flow');
return (
@ -35,7 +35,7 @@ const GenerateForm = ({ onValuesChange, form, node }: IOperatorForm) => {
},
]}
>
<Input.TextArea rows={8} />
<PromptEditor></PromptEditor>
</Form.Item>
<Form.Item
name={['cite']}
@ -49,7 +49,6 @@ const GenerateForm = ({ onValuesChange, form, node }: IOperatorForm) => {
<MessageHistoryWindowSizeItem
initialValue={12}
></MessageHistoryWindowSizeItem>
<DynamicParameters node={node}></DynamicParameters>
</Form>
);
};

View File

@ -1,9 +1,9 @@
import { Form, Input } from 'antd';
import { PromptEditor } from '@/components/prompt-editor';
import { Form } from 'antd';
import { useTranslation } from 'react-i18next';
import { IOperatorForm } from '../../interface';
import DynamicParameters from '../generate-form/dynamic-parameters';
const TemplateForm = ({ onValuesChange, form, node }: IOperatorForm) => {
const TemplateForm = ({ onValuesChange, form }: IOperatorForm) => {
const { t } = useTranslation();
return (
@ -15,10 +15,8 @@ const TemplateForm = ({ onValuesChange, form, node }: IOperatorForm) => {
layout={'vertical'}
>
<Form.Item name={['content']} label={t('flow.content')}>
<Input.TextArea rows={8} placeholder={t('flow.blank')} />
<PromptEditor></PromptEditor>
</Form.Item>
<DynamicParameters node={node}></DynamicParameters>
</Form>
);
};