Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
9a63376e
Commit
9a63376e
authored
Jan 07, 2024
by
Timothy J. Baek
Browse files
feat: file upload error handling
parent
b37b1576
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
42 deletions
+91
-42
backend/apps/rag/main.py
backend/apps/rag/main.py
+1
-0
src/lib/components/chat/MessageInput.svelte
src/lib/components/chat/MessageInput.svelte
+82
-42
src/routes/(app)/+page.svelte
src/routes/(app)/+page.svelte
+8
-0
No files found.
backend/apps/rag/main.py
View file @
9a63376e
...
@@ -28,6 +28,7 @@ from pydantic import BaseModel
...
@@ -28,6 +28,7 @@ from pydantic import BaseModel
from
typing
import
Optional
from
typing
import
Optional
import
uuid
import
uuid
import
time
from
utils.misc
import
calculate_sha256
from
utils.misc
import
calculate_sha256
from
utils.utils
import
get_current_user
from
utils.utils
import
get_current_user
...
...
src/lib/components/chat/MessageInput.svelte
View file @
9a63376e
...
@@ -91,6 +91,26 @@
...
@@ -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(() => {
onMount(() => {
const dropZone = document.querySelector('body');
const dropZone = document.querySelector('body');
...
@@ -123,19 +143,7 @@
...
@@ -123,19 +143,7 @@
if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) {
if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) {
reader.readAsDataURL(file);
reader.readAsDataURL(file);
} else if (['application/pdf', 'text/plain', 'text/csv'].includes(file['type'])) {
} else if (['application/pdf', 'text/plain', 'text/csv'].includes(file['type'])) {
console.log(file);
uploadDoc(file);
const res = await uploadDocToVectorDB(localStorage.token, '', file);
if (res) {
files = [
...files,
{
type: 'doc',
name: file.name,
collection_name: res.collection_name
}
];
}
} else {
} else {
toast.error(`Unsupported File Type '${file['type']}'.`);
toast.error(`Unsupported File Type '${file['type']}'.`);
}
}
...
@@ -241,20 +249,8 @@
...
@@ -241,20 +249,8 @@
if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) {
if (['image/gif', 'image/jpeg', 'image/png'].includes(file['type'])) {
reader.readAsDataURL(file);
reader.readAsDataURL(file);
} else if (['application/pdf', 'text/plain', 'text/csv'].includes(file['type'])) {
} else if (['application/pdf', 'text/plain', 'text/csv'].includes(file['type'])) {
console.log(file);
uploadDoc(file);
const res = await uploadDocToVectorDB(localStorage.token, '', file);
if (res) {
files = [
...files,
{
type: 'doc',
name: file.name,
collection_name: res.collection_name
}
];
filesInputElement.value = '';
filesInputElement.value = '';
}
} else {
} else {
toast.error(`Unsupported File Type '${file['type']}'.`);
toast.error(`Unsupported File Type '${file['type']}'.`);
inputFiles = null;
inputFiles = null;
...
@@ -281,6 +277,7 @@
...
@@ -281,6 +277,7 @@
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"
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"
>
>
<div class="p-2.5 bg-red-400 text-white rounded-lg">
<div class="p-2.5 bg-red-400 text-white rounded-lg">
{#if file.upload_status}
<svg
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
viewBox="0 0 24 24"
...
@@ -296,6 +293,49 @@
...
@@ -296,6 +293,49 @@
d="M12.971 1.816A5.23 5.23 0 0 1 14.25 5.25v1.875c0 .207.168.375.375.375H16.5a5.23 5.23 0 0 1 3.434 1.279 9.768 9.768 0 0 0-6.963-6.963Z"
d="M12.971 1.816A5.23 5.23 0 0 1 14.25 5.25v1.875c0 .207.168.375.375.375H16.5a5.23 5.23 0 0 1 3.434 1.279 9.768 9.768 0 0 0-6.963-6.963Z"
/>
/>
</svg>
</svg>
{:else}
<svg
class=" w-6 h-6 translate-y-[0.5px]"
fill="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
><style>
.spinner_qM83 {
animation: spinner_8HQG 1.05s infinite;
}
.spinner_oXPr {
animation-delay: 0.1s;
}
.spinner_ZTLf {
animation-delay: 0.2s;
}
@keyframes spinner_8HQG {
0%,
57.14% {
animation-timing-function: cubic-bezier(0.33, 0.66, 0.66, 1);
transform: translate(0);
}
28.57% {
animation-timing-function: cubic-bezier(0.33, 0, 0.66, 0.33);
transform: translateY(-6px);
}
100% {
transform: translate(0);
}
}
</style><circle class="spinner_qM83" cx="4" cy="12" r="2.5" /><circle
class="spinner_qM83 spinner_oXPr"
cx="12"
cy="12"
r="2.5"
/><circle
class="spinner_qM83 spinner_ZTLf"
cx="20"
cy="12"
r="2.5"
/></svg
>
{/if}
</div>
</div>
<div class="flex flex-col justify-center -space-y-0.5">
<div class="flex flex-col justify-center -space-y-0.5">
...
...
src/routes/(app)/+page.svelte
View file @
9a63376e
...
@@ -124,6 +124,14 @@
...
@@ -124,6 +124,14 @@
} else if (messages.length != 0 && messages.at(-1).done != true) {
} else if (messages.length != 0 && messages.at(-1).done != true) {
// Response not done
// Response not done
console.log('wait');
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 {
} else {
// Reset chat message textarea height
// Reset chat message textarea height
document.getElementById('chat-textarea').style.height = '';
document.getElementById('chat-textarea').style.height = '';
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment