diff --git a/backend/apps/rag/main.py b/backend/apps/rag/main.py index e55ee8ed..4cde679e 100644 --- a/backend/apps/rag/main.py +++ b/backend/apps/rag/main.py @@ -28,6 +28,7 @@ from pydantic import BaseModel from typing import Optional import uuid +import time from utils.misc import calculate_sha256 from utils.utils import get_current_user diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index 5768be48..c8baab5d 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -91,6 +91,26 @@ } }; + const uploadDoc = async (file) => { + console.log(file); + + const doc = { + type: 'doc', + name: file.name, + collection_name: '', + upload_status: false, + error: '' + }; + + files = [...files, doc]; + const res = await uploadDocToVectorDB(localStorage.token, '', file); + + if (res) { + doc.upload_status = true; + files = files; + } + }; + onMount(() => { const dropZone = document.querySelector('body'); @@ -123,19 +143,7 @@ if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) { reader.readAsDataURL(file); } else if (['application/pdf', 'text/plain', 'text/csv'].includes(file['type'])) { - console.log(file); - const res = await uploadDocToVectorDB(localStorage.token, '', file); - - if (res) { - files = [ - ...files, - { - type: 'doc', - name: file.name, - collection_name: res.collection_name - } - ]; - } + uploadDoc(file); } else { toast.error(`Unsupported File Type '${file['type']}'.`); } @@ -241,20 +249,8 @@ if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) { reader.readAsDataURL(file); } else if (['application/pdf', 'text/plain', 'text/csv'].includes(file['type'])) { - console.log(file); - const res = await uploadDocToVectorDB(localStorage.token, '', file); - - if (res) { - files = [ - ...files, - { - type: 'doc', - name: file.name, - collection_name: res.collection_name - } - ]; - filesInputElement.value = ''; - } + uploadDoc(file); + filesInputElement.value = ''; } else { toast.error(`Unsupported File Type '${file['type']}'.`); inputFiles = null; @@ -281,21 +277,65 @@ class="h-16 w-[15rem] flex items-center space-x-3 px-2.5 dark:bg-gray-600 rounded-xl border border-gray-200 dark:border-none" >
- - - - + {#if file.upload_status} + + + + + {:else} + + {/if}
diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index d433615c..65316941 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -124,6 +124,14 @@ } else if (messages.length != 0 && messages.at(-1).done != true) { // Response not done console.log('wait'); + } else if ( + files.length > 0 && + files.filter((file) => file.upload_status === false).length > 0 + ) { + // Upload not done + toast.error( + `Oops! Hold tight! Your files are still in the processing oven. We're cooking them up to perfection. Please be patient and we'll let you know once they're ready.` + ); } else { // Reset chat message textarea height document.getElementById('chat-textarea').style.height = '';