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" >