diff --git a/web/src/interfaces/database/agent.ts b/web/src/interfaces/database/agent.ts new file mode 100644 index 000000000..b10df254d --- /dev/null +++ b/web/src/interfaces/database/agent.ts @@ -0,0 +1,11 @@ +export interface ICategorizeItem { + name: string; + description?: string; + examples?: { value: string }[]; + index: number; +} + +export type ICategorizeItemResult = Record< + string, + Omit & { examples: string[] } +>; diff --git a/web/src/pages/agent/form/categorize-form/dynamic-categorize.tsx b/web/src/pages/agent/form/categorize-form/dynamic-categorize.tsx index bc4dc9732..7deb4f4ff 100644 --- a/web/src/pages/agent/form/categorize-form/dynamic-categorize.tsx +++ b/web/src/pages/agent/form/categorize-form/dynamic-categorize.tsx @@ -11,7 +11,7 @@ import { FormLabel, FormMessage, } from '@/components/ui/form'; -import { BlurInput, Input } from '@/components/ui/input'; +import { Input } from '@/components/ui/input'; import { BlurTextarea } from '@/components/ui/textarea'; import { useTranslate } from '@/hooks/common-hooks'; import { PlusOutlined } from '@ant-design/icons'; @@ -30,6 +30,7 @@ import { import { UseFormReturn, useFieldArray, useFormContext } from 'react-hook-form'; import { Operator } from '../../constant'; import { useBuildFormSelectOptions } from '../../form-hooks'; +import DynamicExample from './dynamic-example'; interface IProps { nodeId?: string; @@ -130,8 +131,7 @@ const InnerFormSet = ({ nodeId, index }: IProps & { index: number }) => { {t('categoryName')} - - {/* { @@ -142,7 +142,7 @@ const InnerFormSet = ({ nodeId, index }: IProps & { index: number }) => { form.clearErrors(fieldName); } }} - > */} + > @@ -161,51 +161,7 @@ const InnerFormSet = ({ nodeId, index }: IProps & { index: number }) => { )} /> - {/* ( - - {t('examples')} - - + + + )} + /> + {index === 0 ? ( + + ) : ( + + )} + + ))} + + append({ value: '' })} // "" will cause the inability to add, refer to: https://github.com/orgs/react-hook-form/discussions/8485#discussioncomment-2961861 + > + {t('flow.addMessage')} + + + + + ); +}; + +export default memo(DynamicExample); diff --git a/web/src/pages/agent/form/categorize-form/index.tsx b/web/src/pages/agent/form/categorize-form/index.tsx index 7bd906ceb..6d4ddec6a 100644 --- a/web/src/pages/agent/form/categorize-form/index.tsx +++ b/web/src/pages/agent/form/categorize-form/index.tsx @@ -1,3 +1,4 @@ +import { FormContainer } from '@/components/form-container'; import { LargeModelFormField } from '@/components/large-model-form-field'; import { LlmSettingSchema } from '@/components/llm-setting-items/next'; import { MessageHistoryWindowSizeFormField } from '@/components/message-history-window-size-item'; @@ -25,6 +26,7 @@ const CategorizeForm = ({ node }: INextOperatorForm) => { const values = useValues(node); const FormSchema = z.object({ + input: z.string().optional(), parameter: z.string().optional(), ...LlmSettingSchema, message_history_window_size: z.coerce.number(), @@ -33,13 +35,13 @@ const CategorizeForm = ({ node }: INextOperatorForm) => { .object({ name: z.string().min(1, t('flow.nameMessage')).trim(), description: z.string().optional(), - // examples: z - // .array( - // z.object({ - // value: z.string(), - // }), - // ) - // .optional(), + examples: z + .array( + z.object({ + value: z.string(), + }), + ) + .optional(), }) .optional(), ), @@ -60,23 +62,25 @@ const CategorizeForm = ({ node }: INextOperatorForm) => { e.preventDefault(); }} > - ( - - - {t('chat.input')} - - - - - - - )} - /> + + ( + + + {t('chat.input')} + + + + + + + )} + /> - + + diff --git a/web/src/pages/agent/utils.ts b/web/src/pages/agent/utils.ts index 5ca24020e..9d5306f01 100644 --- a/web/src/pages/agent/utils.ts +++ b/web/src/pages/agent/utils.ts @@ -1,9 +1,8 @@ import { - DSLComponents, ICategorizeItem, ICategorizeItemResult, - RAGFlowNodeType, -} from '@/interfaces/database/flow'; +} from '@/interfaces/database/agent'; +import { DSLComponents, RAGFlowNodeType } from '@/interfaces/database/flow'; import { removeUselessFieldsFromValues } from '@/utils/form'; import { Edge, Node, Position, XYPosition } from '@xyflow/react'; import { FormInstance, FormListFieldData } from 'antd'; @@ -391,6 +390,22 @@ export const generateDuplicateNode = ( }; }; +export function convertToStringArray( + list?: Array<{ value: string | number | boolean }>, +) { + if (!Array.isArray(list)) { + return []; + } + return list.map((x) => x.value); +} + +export function convertToObjectArray(list: Array) { + if (!Array.isArray(list)) { + return []; + } + return list.map((x) => ({ value: x })); +} + /** * convert the following object into a list * @@ -411,7 +426,11 @@ export const buildCategorizeListFromObject = ( .reduce>((pre, cur) => { // synchronize edge data to the to field - pre.push({ name: cur, ...categorizeItem[cur] }); + pre.push({ + name: cur, + ...categorizeItem[cur], + examples: convertToObjectArray(categorizeItem[cur].examples), + }); return pre; }, []) .sort((a, b) => a.index - b.index); @@ -424,7 +443,7 @@ export const buildCategorizeListFromObject = ( { "name": "Categorize 1", "description": "111", - "examples": "ddd", + "examples": ["ddd"], "to": "Retrieval:LazyEelsStick" } ] @@ -433,24 +452,11 @@ export const buildCategorizeListFromObject = ( export const buildCategorizeObjectFromList = (list: Array) => { return list.reduce((pre, cur) => { if (cur?.name) { - pre[cur.name] = omit(cur, 'name'); + pre[cur.name] = { + ...omit(cur, 'name', 'examples'), + examples: convertToStringArray(cur.examples), + }; } return pre; }, {}); }; - -export function convertToStringArray( - list: Array<{ value: string | number | boolean }>, -) { - if (!Array.isArray(list)) { - return []; - } - return list.map((x) => x.value); -} - -export function convertToObjectArray(list: Array) { - if (!Array.isArray(list)) { - return []; - } - return list.map((x) => ({ value: x })); -}