diff --git a/docSite/content/zh-cn/docs/development/upgrading/4814.md b/docSite/content/zh-cn/docs/development/upgrading/4814.md index 07ae1b4263ca..5d25134621e3 100644 --- a/docSite/content/zh-cn/docs/development/upgrading/4814.md +++ b/docSite/content/zh-cn/docs/development/upgrading/4814.md @@ -49,3 +49,4 @@ weight: 810 17. 修复 - 反选知识库引用后可能会报错。 18. 修复 - 简易模式转工作流,不是使用最新编辑记录进行转移。 19. 修复 - 表单输入的说明文字不显示。 +20. 修复 - API 无法使用 base64 图片。 diff --git a/packages/global/common/file/tools.ts b/packages/global/common/file/tools.ts index 8cf1d3e955b2..df0de53c0507 100644 --- a/packages/global/common/file/tools.ts +++ b/packages/global/common/file/tools.ts @@ -23,6 +23,11 @@ export const parseUrlToFileType = (url: string): UserChatItemValueItemType['file const parseUrl = new URL(url, 'https://locaohost:3000'); const filename = (() => { + // Check base64 image + if (url.startsWith('data:image/')) { + const mime = url.split(',')[0].split(':')[1].split(';')[0]; + return `image.${mime.split('/')[1]}`; + } // Old version file url: https://xxx.com/file/read?filename=xxx.pdf const filenameQuery = parseUrl.searchParams.get('filename'); if (filenameQuery) return filenameQuery; diff --git a/packages/service/core/chat/utils.ts b/packages/service/core/chat/utils.ts index ef3f81fea8e7..cbca1b1b3aa7 100644 --- a/packages/service/core/chat/utils.ts +++ b/packages/service/core/chat/utils.ts @@ -118,6 +118,11 @@ export const loadRequestMessages = async ({ return item.image_url.url; })(); + // base64 image + if (imgUrl.startsWith('data:image/')) { + return item; + } + try { // If imgUrl is a local path, load image from local, and set url to base64 if (imgUrl.startsWith('/')) { diff --git a/packages/service/core/workflow/dispatch/utils.ts b/packages/service/core/workflow/dispatch/utils.ts index 3a183988b89f..5c625013c373 100644 --- a/packages/service/core/workflow/dispatch/utils.ts +++ b/packages/service/core/workflow/dispatch/utils.ts @@ -129,7 +129,11 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => { return value; }; -export const checkQuoteQAValue = (quoteQA: SearchDataResponseItemType[] = []) => { +export const checkQuoteQAValue = (quoteQA?: SearchDataResponseItemType[]) => { + if (!quoteQA) return undefined; + if (quoteQA.length === 0) { + return []; + } if (quoteQA.some((item) => !item.q || !item.datasetId)) { return undefined; } diff --git a/projects/app/src/pages/api/core/chat/chatTest.ts b/projects/app/src/pages/api/core/chat/chatTest.ts index 2971d728ec4a..9794b251fa82 100644 --- a/projects/app/src/pages/api/core/chat/chatTest.ts +++ b/projects/app/src/pages/api/core/chat/chatTest.ts @@ -199,42 +199,44 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { }); // save chat - const isInteractiveRequest = !!getLastInteractiveValue(histories); - const { text: userInteractiveVal } = chatValue2RuntimePrompt(userQuestion.value); + if (!res.closed) { + const isInteractiveRequest = !!getLastInteractiveValue(histories); + const { text: userInteractiveVal } = chatValue2RuntimePrompt(userQuestion.value); - const newTitle = isPlugin - ? variables.cTime ?? getSystemTime(user.timezone) - : getChatTitleFromChatMessage(userQuestion); + const newTitle = isPlugin + ? variables.cTime ?? getSystemTime(user.timezone) + : getChatTitleFromChatMessage(userQuestion); - const aiResponse: AIChatItemType & { dataId?: string } = { - dataId: responseChatItemId, - obj: ChatRoleEnum.AI, - value: assistantResponses, - [DispatchNodeResponseKeyEnum.nodeResponse]: flowResponses - }; + const aiResponse: AIChatItemType & { dataId?: string } = { + dataId: responseChatItemId, + obj: ChatRoleEnum.AI, + value: assistantResponses, + [DispatchNodeResponseKeyEnum.nodeResponse]: flowResponses + }; - if (isInteractiveRequest) { - await updateInteractiveChat({ - chatId, - appId: app._id, - userInteractiveVal, - aiResponse, - newVariables - }); - } else { - await saveChat({ - chatId, - appId: app._id, - teamId, - tmbId: tmbId, - nodes, - appChatConfig: chatConfig, - variables: newVariables, - isUpdateUseTime: false, // owner update use time - newTitle, - source: ChatSourceEnum.test, - content: [userQuestion, aiResponse] - }); + if (isInteractiveRequest) { + await updateInteractiveChat({ + chatId, + appId: app._id, + userInteractiveVal, + aiResponse, + newVariables + }); + } else { + await saveChat({ + chatId, + appId: app._id, + teamId, + tmbId: tmbId, + nodes, + appChatConfig: chatConfig, + variables: newVariables, + isUpdateUseTime: false, // owner update use time + newTitle, + source: ChatSourceEnum.test, + content: [userQuestion, aiResponse] + }); + } } pushChatUsage({