From bebbba399a1004eaf7d3860648bed84bc0d4d0b9 Mon Sep 17 00:00:00 2001 From: heheer Date: Fri, 16 Aug 2024 15:58:21 +0800 Subject: [PATCH] perf: change value desc position & fix templates (#2413) --- .../global/core/workflow/node/constant.ts | 83 ++++++++----------- .../core/workflow/template/system/aiChat.ts | 2 + .../workflow/template/system/datasetConcat.ts | 6 +- .../workflow/template/system/datasetSearch.ts | 4 +- .../workflow/template/system/runApp/index.ts | 2 + packages/global/core/workflow/type/io.d.ts | 2 + .../appMarketTemplates/CQ/template.json | 12 +-- .../simpleDatasetChat/template.json | 8 +- .../Flow/nodes/NodeDatasetConcat.tsx | 8 +- .../Flow/nodes/NodePluginIO/PluginOutput.tsx | 2 +- .../Flow/nodes/NodeWorkflowStart.tsx | 34 ++++++-- .../render/RenderInput/FieldEditModal.tsx | 2 - .../Flow/nodes/render/RenderInput/Label.tsx | 12 +-- .../templates/DynamicInputs/index.tsx | 2 +- .../templates/SettingQuotePrompt.tsx | 6 +- .../render/RenderOutput/FieldEditModal.tsx | 2 - .../Flow/nodes/render/RenderOutput/Label.tsx | 4 +- .../Flow/nodes/render/ValueTypeLabel.tsx | 11 ++- 18 files changed, 107 insertions(+), 95 deletions(-) diff --git a/packages/global/core/workflow/node/constant.ts b/packages/global/core/workflow/node/constant.ts index 08b860008..d510b1034 100644 --- a/packages/global/core/workflow/node/constant.ts +++ b/packages/global/core/workflow/node/constant.ts @@ -126,61 +126,70 @@ export enum FlowNodeTypeEnum { export const FlowValueTypeMap = { [WorkflowIOValueTypeEnum.string]: { label: 'string', - value: WorkflowIOValueTypeEnum.string, - description: '' + value: WorkflowIOValueTypeEnum.string }, [WorkflowIOValueTypeEnum.number]: { label: 'number', - value: WorkflowIOValueTypeEnum.number, - description: '' + value: WorkflowIOValueTypeEnum.number }, [WorkflowIOValueTypeEnum.boolean]: { label: 'boolean', - value: WorkflowIOValueTypeEnum.boolean, - description: '' + value: WorkflowIOValueTypeEnum.boolean }, [WorkflowIOValueTypeEnum.object]: { label: 'object', - value: WorkflowIOValueTypeEnum.object, - description: '' + value: WorkflowIOValueTypeEnum.object }, [WorkflowIOValueTypeEnum.arrayString]: { label: 'array', - value: WorkflowIOValueTypeEnum.arrayString, - description: '' + value: WorkflowIOValueTypeEnum.arrayString }, [WorkflowIOValueTypeEnum.arrayNumber]: { label: 'array', - value: WorkflowIOValueTypeEnum.arrayNumber, - description: '' + value: WorkflowIOValueTypeEnum.arrayNumber }, [WorkflowIOValueTypeEnum.arrayBoolean]: { label: 'array', - value: WorkflowIOValueTypeEnum.arrayBoolean, - description: '' + value: WorkflowIOValueTypeEnum.arrayBoolean }, [WorkflowIOValueTypeEnum.arrayObject]: { label: 'array', - value: WorkflowIOValueTypeEnum.arrayObject, - description: '' + value: WorkflowIOValueTypeEnum.arrayObject }, [WorkflowIOValueTypeEnum.any]: { label: 'any', - value: WorkflowIOValueTypeEnum.any, - description: '' + value: WorkflowIOValueTypeEnum.any }, [WorkflowIOValueTypeEnum.chatHistory]: { label: '历史记录', - value: WorkflowIOValueTypeEnum.chatHistory, - description: `{ - obj: System | Human | AI; - value: string; -}[]` + value: WorkflowIOValueTypeEnum.chatHistory }, [WorkflowIOValueTypeEnum.datasetQuote]: { label: '知识库引用', - value: WorkflowIOValueTypeEnum.datasetQuote, - description: `{ + value: WorkflowIOValueTypeEnum.datasetQuote + }, + [WorkflowIOValueTypeEnum.selectApp]: { + label: '选择应用', + value: WorkflowIOValueTypeEnum.selectApp + }, + [WorkflowIOValueTypeEnum.selectDataset]: { + label: '选择知识库', + value: WorkflowIOValueTypeEnum.selectDataset + }, + [WorkflowIOValueTypeEnum.dynamic]: { + label: '动态输入', + value: WorkflowIOValueTypeEnum.dynamic + } +}; + +export const EDGE_TYPE = 'default'; +export const defaultNodeVersion = '481'; + +export const chatHistoryValueDesc = `{ + obj: System | Human | AI; + value: string; +}[]`; +export const datasetQuoteValueDesc = `{ id: string; datasetId: string; collectionId: string; @@ -188,26 +197,4 @@ export const FlowValueTypeMap = { sourceId?: string; q: string; a: string -}[]` - }, - [WorkflowIOValueTypeEnum.selectApp]: { - label: '选择应用', - value: WorkflowIOValueTypeEnum.selectApp, - description: '' - }, - [WorkflowIOValueTypeEnum.selectDataset]: { - label: '选择知识库', - value: WorkflowIOValueTypeEnum.selectDataset, - description: `{ - datasetId: string; -}` - }, - [WorkflowIOValueTypeEnum.dynamic]: { - label: '动态输入', - value: WorkflowIOValueTypeEnum.dynamic, - description: '' - } -}; - -export const EDGE_TYPE = 'default'; -export const defaultNodeVersion = '481'; +}[]`; diff --git a/packages/global/core/workflow/template/system/aiChat.ts b/packages/global/core/workflow/template/system/aiChat.ts index a514d537c..7803c550f 100644 --- a/packages/global/core/workflow/template/system/aiChat.ts +++ b/packages/global/core/workflow/template/system/aiChat.ts @@ -1,4 +1,5 @@ import { + chatHistoryValueDesc, FlowNodeInputTypeEnum, FlowNodeOutputTypeEnum, FlowNodeTypeEnum @@ -97,6 +98,7 @@ export const AiChatModule: FlowNodeTemplateType = { label: 'core.module.output.label.New context', description: 'core.module.output.description.New context', valueType: WorkflowIOValueTypeEnum.chatHistory, + valueDesc: chatHistoryValueDesc, type: FlowNodeOutputTypeEnum.static }, { diff --git a/packages/global/core/workflow/template/system/datasetConcat.ts b/packages/global/core/workflow/template/system/datasetConcat.ts index 2b608cad3..0a3eb4fd4 100644 --- a/packages/global/core/workflow/template/system/datasetConcat.ts +++ b/packages/global/core/workflow/template/system/datasetConcat.ts @@ -1,4 +1,5 @@ import { + datasetQuoteValueDesc, FlowNodeInputTypeEnum, FlowNodeOutputTypeEnum, FlowNodeTypeEnum @@ -14,8 +15,6 @@ import { getNanoid } from '../../../../common/string/tools'; import { getHandleConfig } from '../utils'; import { FlowNodeInputItemType } from '../../type/io.d'; -const defaultQuoteKey = 'defaultQuoteKey'; - export const getOneQuoteInputTemplate = ({ key = getNanoid(), index @@ -63,7 +62,8 @@ export const DatasetConcatModule: FlowNodeTemplateType = { key: NodeOutputKeyEnum.datasetQuoteQA, label: 'core.module.Dataset quote.label', type: FlowNodeOutputTypeEnum.static, - valueType: WorkflowIOValueTypeEnum.datasetQuote + valueType: WorkflowIOValueTypeEnum.datasetQuote, + valueDesc: datasetQuoteValueDesc } ] }; diff --git a/packages/global/core/workflow/template/system/datasetSearch.ts b/packages/global/core/workflow/template/system/datasetSearch.ts index 7c5afe2ef..17a10a05c 100644 --- a/packages/global/core/workflow/template/system/datasetSearch.ts +++ b/packages/global/core/workflow/template/system/datasetSearch.ts @@ -1,4 +1,5 @@ import { + datasetQuoteValueDesc, FlowNodeInputTypeEnum, FlowNodeOutputTypeEnum, FlowNodeTypeEnum @@ -118,7 +119,8 @@ export const DatasetSearchModule: FlowNodeTemplateType = { label: 'core.module.Dataset quote.label', description: '特殊数组格式,搜索结果为空时,返回空数组。', type: FlowNodeOutputTypeEnum.static, - valueType: WorkflowIOValueTypeEnum.datasetQuote + valueType: WorkflowIOValueTypeEnum.datasetQuote, + valueDesc: datasetQuoteValueDesc } ] }; diff --git a/packages/global/core/workflow/template/system/runApp/index.ts b/packages/global/core/workflow/template/system/runApp/index.ts index 2d30a28ec..343237c17 100644 --- a/packages/global/core/workflow/template/system/runApp/index.ts +++ b/packages/global/core/workflow/template/system/runApp/index.ts @@ -1,4 +1,5 @@ import { + chatHistoryValueDesc, FlowNodeInputTypeEnum, FlowNodeOutputTypeEnum, FlowNodeTypeEnum @@ -47,6 +48,7 @@ export const RunAppModule: FlowNodeTemplateType = { label: '新的上下文', description: '将该应用回复内容拼接到历史记录中,作为新的上下文返回', valueType: WorkflowIOValueTypeEnum.chatHistory, + valueDesc: chatHistoryValueDesc, required: true, type: FlowNodeOutputTypeEnum.static }, diff --git a/packages/global/core/workflow/type/io.d.ts b/packages/global/core/workflow/type/io.d.ts index 25e41f720..988789ff5 100644 --- a/packages/global/core/workflow/type/io.d.ts +++ b/packages/global/core/workflow/type/io.d.ts @@ -43,6 +43,7 @@ export type FlowNodeInputItemType = InputComponentPropsType & { key: `${NodeInputKeyEnum}` | string; valueType?: WorkflowIOValueTypeEnum; // data type + valueDesc?: string; // data desc value?: any; label: string; debugLabel?: string; @@ -60,6 +61,7 @@ export type FlowNodeOutputItemType = { type: FlowNodeOutputTypeEnum; key: `${NodeOutputKeyEnum}` | string; valueType?: WorkflowIOValueTypeEnum; + valueDesc?: string; value?: any; label?: string; diff --git a/projects/app/public/appMarketTemplates/CQ/template.json b/projects/app/public/appMarketTemplates/CQ/template.json index 97cf4c76b..a0018a01d 100644 --- a/projects/app/public/appMarketTemplates/CQ/template.json +++ b/projects/app/public/appMarketTemplates/CQ/template.json @@ -12,7 +12,7 @@ "name": "系统配置", "intro": "可以配置应用的系统参数", "avatar": "core/workflow/template/systemConfig", - "flowNodeType": "FlowNodeTypeEnum.systemConfig", + "flowNodeType": "userGuide", "position": { "x": 531.2422736065552, "y": -486.7611729549753 @@ -75,7 +75,7 @@ "name": "流程开始", "intro": "", "avatar": "core/workflow/template/workflowStart", - "flowNodeType": "FlowNodeTypeEnum.workflowStart", + "flowNodeType": "workflowStart", "position": { "x": 558.4082376415505, "y": 123.72387429194112 @@ -106,7 +106,7 @@ "name": "AI 对话", "intro": "AI 大模型对话", "avatar": "core/workflow/template/aiChat", - "flowNodeType": "FlowNodeTypeEnum.chatNode", + "flowNodeType": "chatNode", "showStatus": true, "position": { "x": 2701.1267277679685, @@ -229,7 +229,7 @@ "name": "问题分类", "intro": "根据用户的历史记录和当前问题判断该次提问的类型。可以添加多组问题类型,下面是一个模板例子:\n类型1: 打招呼\n类型2: 关于商品\"使用\"问题\n类型3: 关于商品\"购买\"问题\n类型4: 其他问题", "avatar": "core/workflow/template/questionClassify", - "flowNodeType": "FlowNodeTypeEnum.classifyQuestion", + "flowNodeType": "classifyQuestion", "showStatus": true, "position": { "x": 1020.9667229609946, @@ -316,7 +316,7 @@ "name": "指定回复", "intro": "该模块可以直接回复一段指定的内容。常用于引导、提示。非字符串内容传入时,会转成字符串进行输出。", "avatar": "core/workflow/template/reply", - "flowNodeType": "FlowNodeTypeEnum.answerNode", + "flowNodeType": "answerNode", "position": { "x": 1874.9167551056487, "y": 434.98431875888207 @@ -341,7 +341,7 @@ "name": "知识库搜索", "intro": "调用\"语义检索\"和\"全文检索\"能力,从\"知识库\"中查找可能与问题相关的参考内容", "avatar": "core/workflow/template/datasetSearch", - "flowNodeType": "FlowNodeTypeEnum.datasetSearchNode", + "flowNodeType": "datasetSearchNode", "showStatus": true, "position": { "x": 1851.010152279949, diff --git a/projects/app/public/appMarketTemplates/simpleDatasetChat/template.json b/projects/app/public/appMarketTemplates/simpleDatasetChat/template.json index afa55bf5a..dbaf47fb7 100644 --- a/projects/app/public/appMarketTemplates/simpleDatasetChat/template.json +++ b/projects/app/public/appMarketTemplates/simpleDatasetChat/template.json @@ -12,7 +12,7 @@ "name": "系统配置", "intro": "可以配置应用的系统参数", "avatar": "core/workflow/template/systemConfig", - "flowNodeType": "FlowNodeTypeEnum.systemConfig", + "flowNodeType": "userGuide", "position": { "x": 531.2422736065552, "y": -486.7611729549753 @@ -75,7 +75,7 @@ "name": "流程开始", "intro": "", "avatar": "core/workflow/template/workflowStart", - "flowNodeType": "FlowNodeTypeEnum.workflowStart", + "flowNodeType": "workflowStart", "position": { "x": 558.4082376415505, "y": 123.72387429194112 @@ -106,7 +106,7 @@ "name": "AI 对话", "intro": "AI 大模型对话", "avatar": "core/workflow/template/aiChat", - "flowNodeType": "FlowNodeTypeEnum.chatNode", + "flowNodeType": "chatNode", "showStatus": true, "position": { "x": 1638.509551404687, @@ -229,7 +229,7 @@ "name": "知识库搜索", "intro": "调用\"语义检索\"和\"全文检索\"能力,从\"知识库\"中查找可能与问题相关的参考内容", "avatar": "core/workflow/template/datasetSearch", - "flowNodeType": "FlowNodeTypeEnum.datasetSearchNode", + "flowNodeType": "datasetSearchNode", "showStatus": true, "position": { "x": 918.5901682164496, diff --git a/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/NodeDatasetConcat.tsx b/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/NodeDatasetConcat.tsx index 1585ea981..64cae6d63 100644 --- a/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/NodeDatasetConcat.tsx +++ b/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/NodeDatasetConcat.tsx @@ -7,11 +7,7 @@ import RenderInput from './render/RenderInput'; import { Box, Button, Flex, HStack } from '@chakra-ui/react'; import { useTranslation } from 'next-i18next'; import { SmallAddIcon } from '@chakra-ui/icons'; -import { - WorkflowIOValueTypeEnum, - NodeInputKeyEnum, - VARIABLE_NODE_ID -} from '@fastgpt/global/core/workflow/constants'; +import { NodeInputKeyEnum, VARIABLE_NODE_ID } from '@fastgpt/global/core/workflow/constants'; import { getOneQuoteInputTemplate } from '@fastgpt/global/core/workflow/template/system/datasetConcat'; import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant'; import { useSystemStore } from '@/web/common/system/useSystemStore'; @@ -189,7 +185,7 @@ function Reference({ {inputChildren.label} {/* value */} - + {input.label} {input.description && } {/* value */} - + ) => { t }); - return variables.map((item) => ({ - id: item.key, - type: FlowNodeOutputTypeEnum.static, - key: item.key, - required: item.required, - valueType: item.valueType || WorkflowIOValueTypeEnum.any, - label: item.label - })); + return variables.map((item) => { + if (item.valueType === WorkflowIOValueTypeEnum.chatHistory) { + return { + id: item.key, + type: FlowNodeOutputTypeEnum.static, + key: item.key, + required: item.required, + valueType: item.valueType, + valueDesc: chatHistoryValueDesc, + label: item.label + }; + } + return { + id: item.key, + type: FlowNodeOutputTypeEnum.static, + key: item.key, + required: item.required, + valueType: item.valueType || WorkflowIOValueTypeEnum.any, + label: item.label + }; + }); }, [nodeList, t]); // Dynamic add or delete userFilesInput diff --git a/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/render/RenderInput/FieldEditModal.tsx b/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/render/RenderInput/FieldEditModal.tsx index e774d27b0..303cdf024 100644 --- a/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/render/RenderInput/FieldEditModal.tsx +++ b/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/render/RenderInput/FieldEditModal.tsx @@ -24,8 +24,6 @@ import { useForm } from 'react-hook-form'; import { useTranslation } from 'next-i18next'; import { useMount } from 'ahooks'; import FormLabel from '@fastgpt/web/components/common/MyBox/FormLabel'; -import { useContextSelector } from 'use-context-selector'; -import { WorkflowContext } from '../../../../context'; const FieldModal = ({ customInputConfig, diff --git a/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/render/RenderInput/Label.tsx b/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/render/RenderInput/Label.tsx index 59b7070ee..60cc135d2 100644 --- a/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/render/RenderInput/Label.tsx +++ b/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/render/RenderInput/Label.tsx @@ -1,7 +1,7 @@ import { FlowNodeInputItemType } from '@fastgpt/global/core/workflow/type/io.d'; import React, { useCallback, useMemo } from 'react'; import { useTranslation } from 'next-i18next'; -import { Box, Flex, HStack } from '@chakra-ui/react'; +import { Box, Flex } from '@chakra-ui/react'; import NodeInputSelect from '@fastgpt/web/components/core/workflow/NodeInputSelect'; import { FlowNodeInputTypeEnum } from '@fastgpt/global/core/workflow/node/constant'; @@ -10,9 +10,6 @@ import { useContextSelector } from 'use-context-selector'; import { WorkflowContext } from '@/pages/app/detail/components/WorkflowComponents/context'; import QuestionTip from '@fastgpt/web/components/common/MyTooltip/QuestionTip'; import FormLabel from '@fastgpt/web/components/common/MyBox/FormLabel'; -import MyTooltip from '@fastgpt/web/components/common/MyTooltip'; -import MyIcon from '@fastgpt/web/components/common/Icon'; -import MyTag from '@fastgpt/web/components/common/Tag/index'; import VariableTip from '@/components/common/Textarea/MyTextarea/VariableTip'; type Props = { @@ -25,7 +22,8 @@ const InputLabel = ({ nodeId, input }: Props) => { const onChangeNode = useContextSelector(WorkflowContext, (v) => v.onChangeNode); - const { description, required, label, selectedTypeIndex, renderTypeList, valueType } = input; + const { description, required, label, selectedTypeIndex, renderTypeList, valueType, valueDesc } = + input; const onChangeRenderType = useCallback( (e: string) => { @@ -60,7 +58,9 @@ const InputLabel = ({ nodeId, input }: Props) => { {description && } {/* value type */} - {renderType === FlowNodeInputTypeEnum.reference && } + {renderType === FlowNodeInputTypeEnum.reference && ( + + )} {/* input type select */} {renderTypeList && renderTypeList.length > 1 && ( diff --git a/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/render/RenderInput/templates/DynamicInputs/index.tsx b/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/render/RenderInput/templates/DynamicInputs/index.tsx index 5d544ac2b..6eb6bc289 100644 --- a/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/render/RenderInput/templates/DynamicInputs/index.tsx +++ b/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/nodes/render/RenderInput/templates/DynamicInputs/index.tsx @@ -184,7 +184,7 @@ function Reference({ )} {/* value */} - + { {t('common:core.module.Dataset quote.label')} - + { const { t } = useTranslation(); - const { label = '', description, valueType } = output; + const { label = '', description, valueType, valueDesc } = output; const Render = useMemo(() => { return ( @@ -36,7 +36,7 @@ const OutputLabel = ({ nodeId, output }: { nodeId: string; output: FlowNodeOutpu {t(label as any)} {description && } - + {output.type === FlowNodeOutputTypeEnum.source && ( { +const ValueTypeLabel = ({ + valueType, + valueDesc +}: { + valueType?: WorkflowIOValueTypeEnum; + valueDesc?: string; +}) => { const valueTypeData = valueType ? FlowValueTypeMap[valueType] : undefined; const label = valueTypeData?.label || ''; - const description = valueTypeData?.description || ''; return !!label ? ( - +