From 86bd1c90cea2d36f1110292c1ca7e841b04fa34b Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Mon, 25 Nov 2024 21:47:22 +0800 Subject: [PATCH 1/2] perf: code --- .../zh-cn/docs/development/upgrading/4814.md | 3 ++ .../core/workflow/dispatch/chat/oneapi.ts | 3 +- .../service/core/workflow/dispatch/utils.ts | 29 +++++------------- .../common/MySelect/MultipleRowSelect.tsx | 7 +++-- .../web/components/common/MySelect/type.d.ts | 2 +- .../core/chat/ChatContainer/ChatBox/index.tsx | 30 ++++++++++++------- projects/app/src/global/core/app/api.d.ts | 1 - .../pages/api/core/app/transitionWorkflow.ts | 4 +-- .../src/pages/api/core/app/version/publish.ts | 27 ++++++++--------- .../detail/components/SimpleApp/AppCard.tsx | 26 ++++------------ .../detail/components/SimpleApp/ChatTest.tsx | 3 +- .../detail/components/SimpleApp/Header.tsx | 1 - .../WorkflowComponents/Flow/ChatTest.tsx | 3 +- .../app/detail/components/useChatTest.tsx | 5 +++- 14 files changed, 66 insertions(+), 78 deletions(-) diff --git a/docSite/content/zh-cn/docs/development/upgrading/4814.md b/docSite/content/zh-cn/docs/development/upgrading/4814.md index d5d70189edc..ba7c15efe53 100644 --- a/docSite/content/zh-cn/docs/development/upgrading/4814.md +++ b/docSite/content/zh-cn/docs/development/upgrading/4814.md @@ -16,3 +16,6 @@ weight: 810 5. 优化 - 应用编辑记录采用 diff 存储,避免浏览器溢出。 6. 修复 - 分块策略,四级标题会被丢失。 同时新增了五级标题的支持。 7. 修复 - MongoDB 知识库集合唯一索引。 +8. 修复 - 反选知识库引用后可能会报错。 +9. 修复 - 简易模式转工作流,不是使用最新编辑记录进行转移。 +10. 修复 - 表单输入的说明文字不显示。 diff --git a/packages/service/core/workflow/dispatch/chat/oneapi.ts b/packages/service/core/workflow/dispatch/chat/oneapi.ts index 2695166812e..59cfe7afbdd 100644 --- a/packages/service/core/workflow/dispatch/chat/oneapi.ts +++ b/packages/service/core/workflow/dispatch/chat/oneapi.ts @@ -33,7 +33,7 @@ import { getLLMModel, ModelTypeEnum } from '../../../ai/model'; import type { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type'; import { NodeInputKeyEnum, NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants'; import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants'; -import { getHistories } from '../utils'; +import { checkQuoteQAValue, getHistories } from '../utils'; import { filterSearchResultsByMaxChars } from '../../utils'; import { getHistoryPreview } from '@fastgpt/global/core/chat/utils'; import { computedMaxToken, llmCompletionsBodyFormat } from '../../../ai/utils'; @@ -91,6 +91,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise edge.target); }; -// export const checkTheModuleConnectedByTool = ( -// modules: StoreNodeItemType[], -// node: StoreNodeItemType -// ) => { -// let sign = false; -// const toolModules = modules.filter((item) => item.flowNodeType === FlowNodeTypeEnum.tools); - -// toolModules.forEach((item) => { -// const toolOutput = item.outputs.find( -// (output) => output.key === NodeOutputKeyEnum.selectedTools -// ); -// toolOutput?.targets.forEach((target) => { -// if (target.moduleId === node.moduleId) { -// sign = true; -// } -// }); -// }); - -// return sign; -// }; - export const getHistories = (history?: ChatItemType[] | number, histories: ChatItemType[] = []) => { if (!history) return []; @@ -149,6 +129,13 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => { return value; }; +export const checkQuoteQAValue = (quoteQA: SearchDataResponseItemType[] = []) => { + if (quoteQA.some((item) => !item.q || !item.datasetId)) { + return undefined; + } + return quoteQA; +}; + /* remove system variable */ export const removeSystemVariable = (variables: Record) => { const copyVariables = { ...variables }; diff --git a/packages/web/components/common/MySelect/MultipleRowSelect.tsx b/packages/web/components/common/MySelect/MultipleRowSelect.tsx index 4b71bd5a7ba..545938fb8c4 100644 --- a/packages/web/components/common/MySelect/MultipleRowSelect.tsx +++ b/packages/web/components/common/MySelect/MultipleRowSelect.tsx @@ -60,8 +60,11 @@ export const MultipleRowSelect = ({ const newValue = [...cloneValue]; if (item.value === selectedValue) { - setCloneValue([undefined]); - onSelect(undefined); + for (let i = index; i < newValue.length; i++) { + newValue[i] = undefined; + } + setCloneValue(newValue); + onSelect(newValue); } else { newValue[index] = item.value; setCloneValue(newValue); diff --git a/packages/web/components/common/MySelect/type.d.ts b/packages/web/components/common/MySelect/type.d.ts index 8b5839ff019..2b4831c6372 100644 --- a/packages/web/components/common/MySelect/type.d.ts +++ b/packages/web/components/common/MySelect/type.d.ts @@ -11,7 +11,7 @@ export type MultipleSelectProps = { list: ListItemType[]; emptyTip?: string; maxH?: number; - onSelect: (val: any[] | undefined) => void; + onSelect: (val: any[]) => void; styles?: ButtonProps; popDirection?: 'top' | 'bottom'; }; diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/index.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/index.tsx index a5c6729f20e..5cd1a9ec745 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/index.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/index.tsx @@ -83,6 +83,7 @@ enum FeedbackTypeEnum { type Props = OutLinkChatAuthProps & ChatProviderProps & { + isReady?: boolean; feedbackType?: `${FeedbackTypeEnum}`; showMarkIcon?: boolean; // admin mark dataset showVoiceIcon?: boolean; @@ -97,6 +98,7 @@ type Props = OutLinkChatAuthProps & }; const ChatBox = ({ + isReady = true, feedbackType = FeedbackTypeEnum.hidden, showMarkIcon = false, showVoiceIcon = true, @@ -811,7 +813,7 @@ const ChatBox = ({ setQuestionGuide([]); setValue('chatStarted', false); abortRequest('leave'); - }, [router.query, setValue, chatId, abortRequest]); + }, [router.query, setValue, chatId]); // add listener useEffect(() => { @@ -840,6 +842,22 @@ const ChatBox = ({ }; }, [resetInputVal, sendPrompt]); + // Auto send prompt + useEffect(() => { + if ( + isReady && + autoExecute.open && + chatStarted && + chatRecords.length === 0 && + isChatRecordsLoaded + ) { + sendPrompt({ + text: autoExecute.defaultPrompt || 'AUTO_EXECUTE', + hideInUI: true + }); + } + }, [isReady, chatStarted, autoExecute?.open, chatRecords, isChatRecordsLoaded]); + // output data useImperativeHandle(ChatBoxRef, () => ({ restartChat() { @@ -854,16 +872,6 @@ const ChatBox = ({ } })); - // Auto send prompt - useEffect(() => { - if (autoExecute.open && chatStarted && chatRecords.length === 0 && isChatRecordsLoaded) { - sendPrompt({ - text: autoExecute.defaultPrompt || 'AUTO_EXECUTE', - hideInUI: true - }); - } - }, [sendPrompt, chatStarted, autoExecute, chatRecords, isChatRecordsLoaded]); - const RenderRecords = useMemo(() => { return ( ): Promise<{}> { +async function handler( + req: ApiRequestProps, + res: NextApiResponse +): Promise<{}> { const { appId } = req.query as { appId: string }; - const { - nodes = [], - edges = [], - chatConfig, - type, - isPublish, - versionName - } = req.body as PostPublishAppProps; + const { nodes = [], edges = [], chatConfig, isPublish, versionName } = req.body; const { tmbId } = await authApp({ appId, req, per: WritePermissionVal, authToken: true }); @@ -50,11 +47,13 @@ async function handler(req: NextApiRequest, res: NextApiResponse): Promise< chatConfig, updateTime: new Date(), version: 'v2', - type, - scheduledTriggerConfig: chatConfig?.scheduledTriggerConfig, - scheduledTriggerNextTime: chatConfig?.scheduledTriggerConfig?.cronString - ? getNextTimeByCronStringAndTimezone(chatConfig.scheduledTriggerConfig) - : null, + // 只有发布才会更新定时器 + ...(isPublish && { + scheduledTriggerConfig: chatConfig?.scheduledTriggerConfig, + scheduledTriggerNextTime: chatConfig?.scheduledTriggerConfig?.cronString + ? getNextTimeByCronStringAndTimezone(chatConfig.scheduledTriggerConfig) + : null + }), 'pluginData.nodeVersion': _id }, { diff --git a/projects/app/src/pages/app/detail/components/SimpleApp/AppCard.tsx b/projects/app/src/pages/app/detail/components/SimpleApp/AppCard.tsx index ebd85eed65c..31226c5bc46 100644 --- a/projects/app/src/pages/app/detail/components/SimpleApp/AppCard.tsx +++ b/projects/app/src/pages/app/detail/components/SimpleApp/AppCard.tsx @@ -22,9 +22,7 @@ import MyMenu from '@fastgpt/web/components/common/MyMenu'; import MyModal from '@fastgpt/web/components/common/MyModal'; import { useRequest2 } from '@fastgpt/web/hooks/useRequest'; import { postTransition2Workflow } from '@/web/core/app/api/app'; -import { AppTypeEnum } from '@fastgpt/global/core/app/constants'; import { form2AppWorkflow } from '@/web/core/app/utils'; -import { formatTime2YMDHMS } from '@fastgpt/global/common/string/time'; import { SimpleAppSnapshotType } from './useSnapshots'; const AppCard = ({ @@ -38,7 +36,6 @@ const AppCard = ({ const { t } = useTranslation(); const onSaveApp = useContextSelector(AppContext, (v) => v.onSaveApp); const appDetail = useContextSelector(AppContext, (v) => v.appDetail); - const setAppDetail = useContextSelector(AppContext, (v) => v.setAppDetail); const onOpenInfoEdit = useContextSelector(AppContext, (v) => v.onOpenInfoEdit); const onDelApp = useContextSelector(AppContext, (v) => v.onDelApp); @@ -55,22 +52,11 @@ const AppCard = ({ nodes, edges, chatConfig: appForm.chatConfig, - type: AppTypeEnum.simple, - isPublish: true, - versionName: formatTime2YMDHMS(new Date()) + isPublish: false, + versionName: t('app:transition_to_workflow') }); - setPast((prevPast) => - prevPast.map((item, index) => - index === 0 - ? { - ...item, - isSaved: true - } - : item - ) - ); - return await postTransition2Workflow({ appId, createNew: transitionCreateNew }); + return postTransition2Workflow({ appId, createNew: transitionCreateNew }); }, { onSuccess: ({ id }) => { @@ -81,10 +67,8 @@ const AppCard = ({ } }); } else { - setAppDetail((state) => ({ - ...state, - type: AppTypeEnum.workflow - })); + setPast([]); + router.reload(); } }, successToast: t('common:common.Success') diff --git a/projects/app/src/pages/app/detail/components/SimpleApp/ChatTest.tsx b/projects/app/src/pages/app/detail/components/SimpleApp/ChatTest.tsx index df77119b2c5..ac63c0e26da 100644 --- a/projects/app/src/pages/app/detail/components/SimpleApp/ChatTest.tsx +++ b/projects/app/src/pages/app/detail/components/SimpleApp/ChatTest.tsx @@ -39,7 +39,8 @@ const ChatTest = ({ appForm }: Props) => { const { ChatContainer, restartChat, loading } = useChatTest({ ...workflowData, - chatConfig: appForm.chatConfig + chatConfig: appForm.chatConfig, + isReady: true }); return ( diff --git a/projects/app/src/pages/app/detail/components/SimpleApp/Header.tsx b/projects/app/src/pages/app/detail/components/SimpleApp/Header.tsx index 33f708e1922..8deeb509538 100644 --- a/projects/app/src/pages/app/detail/components/SimpleApp/Header.tsx +++ b/projects/app/src/pages/app/detail/components/SimpleApp/Header.tsx @@ -87,7 +87,6 @@ const Header = ({ nodes, edges, chatConfig: appForm.chatConfig, - type: AppTypeEnum.simple, isPublish, versionName }); diff --git a/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/ChatTest.tsx b/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/ChatTest.tsx index 4b903f75542..87e27c03c42 100644 --- a/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/ChatTest.tsx +++ b/projects/app/src/pages/app/detail/components/WorkflowComponents/Flow/ChatTest.tsx @@ -36,7 +36,8 @@ const ChatTest = ({ isOpen, nodes = [], edges = [], onClose }: Props) => { const { restartChat, ChatContainer, loading } = useChatTest({ nodes, edges, - chatConfig: appDetail.chatConfig + chatConfig: appDetail.chatConfig, + isReady: isOpen }); const pluginRunTab = useContextSelector(ChatItemContext, (v) => v.pluginRunTab); const setPluginRunTab = useContextSelector(ChatItemContext, (v) => v.setPluginRunTab); diff --git a/projects/app/src/pages/app/detail/components/useChatTest.tsx b/projects/app/src/pages/app/detail/components/useChatTest.tsx index e1a8ece508d..f69e8d66eed 100644 --- a/projects/app/src/pages/app/detail/components/useChatTest.tsx +++ b/projects/app/src/pages/app/detail/components/useChatTest.tsx @@ -24,11 +24,13 @@ const PluginRunBox = dynamic(() => import('@/components/core/chat/ChatContainer/ export const useChatTest = ({ nodes, edges, - chatConfig + chatConfig, + isReady }: { nodes: StoreNodeItemType[]; edges: StoreEdgeItemType[]; chatConfig: AppChatConfigType; + isReady: boolean; }) => { const { t } = useTranslation(); const { userInfo } = useUserStore(); @@ -130,6 +132,7 @@ export const useChatTest = ({ ) : ( Date: Mon, 25 Nov 2024 21:49:11 +0800 Subject: [PATCH 2/2] update doc --- .../zh-cn/docs/development/upgrading/4814.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/docSite/content/zh-cn/docs/development/upgrading/4814.md b/docSite/content/zh-cn/docs/development/upgrading/4814.md index ba7c15efe53..11ace654a46 100644 --- a/docSite/content/zh-cn/docs/development/upgrading/4814.md +++ b/docSite/content/zh-cn/docs/development/upgrading/4814.md @@ -12,10 +12,11 @@ weight: 810 1. 新增 - 工作流支持进入聊天框/点击开始对话后,自动触发一轮对话。 2. 新增 - 重写 chatContext,对话测试也会有日志,并且刷新后不会丢失对话。 3. 新增 - 分享链接支持配置是否允许查看原文。 -4. 优化 - 工作流 ui 细节。 -5. 优化 - 应用编辑记录采用 diff 存储,避免浏览器溢出。 -6. 修复 - 分块策略,四级标题会被丢失。 同时新增了五级标题的支持。 -7. 修复 - MongoDB 知识库集合唯一索引。 -8. 修复 - 反选知识库引用后可能会报错。 -9. 修复 - 简易模式转工作流,不是使用最新编辑记录进行转移。 -10. 修复 - 表单输入的说明文字不显示。 +4. 新增 - 新的 doc2x 插件。 +5. 优化 - 工作流 ui 细节。 +6. 优化 - 应用编辑记录采用 diff 存储,避免浏览器溢出。 +7. 修复 - 分块策略,四级标题会被丢失。 同时新增了五级标题的支持。 +8. 修复 - MongoDB 知识库集合唯一索引。 +9. 修复 - 反选知识库引用后可能会报错。 +10. 修复 - 简易模式转工作流,不是使用最新编辑记录进行转移。 +11. 修复 - 表单输入的说明文字不显示。