Timothy J. Baek 7 ヶ月 前
コミット
6afc686e17

+ 1 - 1
backend/open_webui/apps/retrieval/utils.py

@@ -319,7 +319,7 @@ def get_rag_context(
     for file in files:
         if file.get("context") == "full":
             context = {
-                "documents": [[file["content"]]],
+                "documents": [[file.get("file").get("content")]],
                 "metadatas": [[{"file_id": file.get("id"), "name": file.get("name")}]],
             }
         else:

+ 4 - 1
src/lib/components/chat/MessageInput.svelte

@@ -150,7 +150,10 @@
 			if (res) {
 				fileItem.status = 'processed';
 				fileItem.collection_name = res.collection_name;
-				fileItem.content = res.content;
+				fileItem.file = {
+					...fileItem.file,
+					content: res.content
+				};
 
 				files = files;
 			}

+ 9 - 3
src/lib/components/chat/MessageInput/Commands.svelte

@@ -46,14 +46,17 @@
 			if (res) {
 				fileItem.status = 'processed';
 				fileItem.collection_name = res.collection_name;
-				fileItem.content = res.content;
+				fileItem.file = {
+					content: res.content,
+					...fileItem.file
+				};
 
 				files = files;
 			}
 		} catch (e) {
 			// Remove the failed doc from the files array
 			files = files.filter((f) => f.name !== url);
-			toast.error(e);
+			toast.error(JSON.stringify(e));
 		}
 	};
 
@@ -76,7 +79,10 @@
 			if (res) {
 				fileItem.status = 'processed';
 				fileItem.collection_name = res.collection_name;
-				fileItem.content = res.content;
+				fileItem.file = {
+					content: res.content,
+					...fileItem.file
+				};
 				files = files;
 			}
 		} catch (e) {

+ 1 - 1
src/lib/components/common/FileItem.svelte

@@ -33,7 +33,7 @@
 		class="h-14 {className} flex items-center space-x-3 {colorClassName} rounded-xl border border-gray-100 dark:border-gray-800 text-left"
 		type="button"
 		on:click={async () => {
-			if (file.content) {
+			if (file?.file?.content) {
 				showModal = !showModal;
 			} else {
 				if (url) {

+ 5 - 3
src/lib/components/common/FileItemModal.svelte

@@ -61,8 +61,10 @@
 						{/if}
 
-						{#if file.content}
-							<div class="capitalize shrink-0">{getLineCount(file.content)} extracted lines</div>
+						{#if file?.file?.content}
+							<div class="capitalize shrink-0">
+								{getLineCount(file?.file?.content ?? '')} extracted lines
+							</div>
 
 							<div class="flex items-center gap-1 shrink-0">
 								<Info />
@@ -100,7 +102,7 @@
 		</div>
 
 		<div class="max-h-96 overflow-scroll scrollbar-hidden text-xs whitespace-pre-wrap">
-			{file?.content ?? 'No content'}
+			{file?.file?.content ?? 'No content'}
 		</div>
 	</div>
 </Modal>

+ 2 - 1
src/lib/utils/index.ts

@@ -889,5 +889,6 @@ export const formatFileSize = (size) => {
 };
 
 export const getLineCount = (text) => {
-	return text.split('\n').length;
+	console.log(typeof text);
+	return text ? text.split('\n').length : 0;
 };