Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix: Fixed the issue of error reporting when uploading files in the chat box #2897 (#2898)

balibabu526fcbbfde65
diff --git a/web/src/components/message-input/index.tsx b/web/src/components/message-input/index.tsx
index fb9ea4c9df..d786869c0b 100644
--- a/web/src/components/message-input/index.tsx
+++ b/web/src/components/message-input/index.tsx
@@ -52,11 +52,6 @@ const getFileIds = (fileList: UploadFile[]) => {
return ids;
};
-const isUploadError = (file: UploadFile) => {
- const retcode = get(file, 'response.retcode');
- return typeof retcode === 'number' && retcode !== 0;
-};
-
const isUploadSuccess = (file: UploadFile) => {
const retcode = get(file, 'response.retcode');
return typeof retcode === 'number' && retcode === 0;
@@ -121,7 +116,7 @@ const MessageInput = ({
const creatingRet = await createConversationBeforeUploadDocument(
file.name,
);
- if (creatingRet.retcode === 0) {
+ if (creatingRet?.retcode === 0) {
nextConversationId = creatingRet.data.id;
}
}
@@ -133,6 +128,7 @@ const MessageInput = ({
});
return [...list];
});
+
const ret = await uploadAndParseDocument({
conversationId: nextConversationId,
fileList: [file],
@@ -217,18 +213,12 @@ const MessageInput = ({
<Space>
{showUploadIcon && (
<Upload
- // action={uploadUrl}
- // fileList={fileList}
onPreview={handlePreview}
onChange={handleChange}
multiple={false}
- // headers={{ [Authorization]: getAuthorization() }}
- // data={{ conversation_id: conversationId }}
- // method="post"
onRemove={handleRemove}
showUploadList={false}
- beforeUpload={(file, fileList) => {
- console.log('πŸš€ ~ beforeUpload:', fileList);
+ beforeUpload={() => {
return false;
}}
>
@@ -283,17 +273,14 @@ const MessageInput = ({
<List.Item>
<Card className={styles.documentCard}>
<Flex gap={10} align="center">
- {item.status === 'uploading' || !item.response ? (
+ {item.status === 'uploading' ? (
<Spin
indicator={
<LoadingOutlined style={{ fontSize: 24 }} spin />
}
/>
- ) : !getFileId(item) ? (
- <InfoCircleOutlined
- size={30}
- // width={30}
- ></InfoCircleOutlined>
+ ) : item.status === 'error' ? (
+ <InfoCircleOutlined size={30}></InfoCircleOutlined>
) : (
<FileIcon id={id} name={fileName}></FileIcon>
)}
@@ -304,7 +291,7 @@ const MessageInput = ({
>
<b> {fileName}</b>
</Text>
- {isUploadError(item) ? (
+ {item.status === 'error' ? (
t('uploadFailed')
) : (
<>
diff --git a/web/src/hooks/document-hooks.ts b/web/src/hooks/document-hooks.ts
index 8c952e2587..1ee4384dd2 100644
--- a/web/src/hooks/document-hooks.ts
+++ b/web/src/hooks/document-hooks.ts
@@ -422,17 +422,21 @@ export const useUploadAndParseDocument = (uploadMethod: string) => {
conversationId: string;
fileList: UploadFile[];
}) => {
- const formData = new FormData();
- formData.append('conversation_id', conversationId);
- fileList.forEach((file: UploadFile) => {
- formData.append('file', file as any);
- });
- if (uploadMethod === 'upload_and_parse') {
- const data = await kbService.upload_and_parse(formData);
+ try {
+ const formData = new FormData();
+ formData.append('conversation_id', conversationId);
+ fileList.forEach((file: UploadFile) => {
+ formData.append('file', file as any);
+ });
+ if (uploadMethod === 'upload_and_parse') {
+ const data = await kbService.upload_and_parse(formData);
+ return data?.data;
+ }
+ const data = await chatService.uploadAndParseExternal(formData);
return data?.data;
+ } catch (error) {
+ console.log('πŸš€ ~ useUploadAndParseDocument ~ error:', error);
}
- const data = await chatService.uploadAndParseExternal(formData);
- return data?.data;
},
});
diff --git a/web/src/pages/chat/hooks.ts b/web/src/pages/chat/hooks.ts
index 7444990dcc..bc0348a8a5 100644
--- a/web/src/pages/chat/hooks.ts
+++ b/web/src/pages/chat/hooks.ts
@@ -582,14 +582,18 @@ export const useSendButtonDisabled = (value: string) => {
export const useCreateConversationBeforeUploadDocument = () => {
const { setConversation } = useSetConversation();
const { dialogId } = useGetChatSearchParams();
+ const { getConversationIsNew } = useSetChatRouteParams();
const createConversationBeforeUploadDocument = useCallback(
async (message: string) => {
- const data = await setConversation(message, true);
+ const isNew = getConversationIsNew();
+ if (isNew === 'true') {
+ const data = await setConversation(message, true);
- return data;
+ return data;
+ }
},
- [setConversation],
+ [setConversation, getConversationIsNew],
);
return {
diff --git a/web/src/pages/chat/markdown-content/index.less b/web/src/pages/chat/markdown-content/index.less
index caa208017f..66f9c6a6f1 100644
--- a/web/src/pages/chat/markdown-content/index.less
+++ b/web/src/pages/chat/markdown-content/index.less
@@ -43,3 +43,8 @@
}
}
}
+
+.fileThumbnail {
+ display: inline-block;
+ max-width: 40px;
+}
diff --git a/web/src/pages/chat/markdown-content/index.tsx b/web/src/pages/chat/markdown-content/index.tsx
index db3d1504e6..156a8950db 100644
--- a/web/src/pages/chat/markdown-content/index.tsx
+++ b/web/src/pages/chat/markdown-content/index.tsx
@@ -118,7 +118,11 @@ const MarkdownContent = ({
{documentId && (
<Flex gap={'small'}>
{fileThumbnail ? (
- <img src={fileThumbnail} alt="" />
+ <img
+ src={fileThumbnail}
+ alt=""
+ className={styles.fileThumbnail}
+ />
) : (
<SvgIcon
name={`file-icon/${fileExtension}`}
diff --git a/web/src/services/knowledge-service.ts b/web/src/services/knowledge-service.ts
index 17d4bc7476..2804cca58f 100644
--- a/web/src/services/knowledge-service.ts
+++ b/web/src/services/knowledge-service.ts
@@ -1,7 +1,6 @@
import api from '@/utils/api';
import registerServer from '@/utils/register-server';
import request from '@/utils/request';
-import pureRequest from 'umi-request';
const {
create_kb,
@@ -25,7 +24,6 @@ const {
retrieval_test,
document_rename,
document_run,
- get_document_file,
document_upload,
web_crawl,
knowledge_graph,
@@ -145,39 +143,4 @@ const methods = {
const kbService = registerServer<keyof typeof methods>(methods, request);
-export const getDocumentFile = (documentId: string) => {
- return pureRequest(get_document_file + '/' + documentId, {
- responseType: 'blob',
- method: 'get',
- parseResponse: false,
- // getResponse: true,
- })
- .then((res) => {
- const x = res.headers.get('content-disposition');
- console.info(res);
- console.info(x);
- return res.blob();
- })
- .then((res) => {
- // const objectURL = URL.createObjectURL(res);
-
- // let btn = document.createElement('a');
-
- // btn.download = '文仢名.pdf';
-
- // btn.href = objectURL;
-
- // btn.click();
-
- // URL.revokeObjectURL(objectURL);
-
- // btn = null;
-
- return res;
- })
- .catch((err) => {
- console.info(err);
- });
-};
-
export default kbService;