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
6681df29
Commit
6681df29
authored
Jul 31, 2024
by
Clivia
Browse files
⚡
Initialize fileItem first to speed up file display
parent
9d58bb1c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
32 deletions
+43
-32
src/lib/components/chat/MessageInput.svelte
src/lib/components/chat/MessageInput.svelte
+43
-32
No files found.
src/lib/components/chat/MessageInput.svelte
View file @
6681df29
<script lang="ts">
<script lang="ts">
import { toast } from 'svelte-sonner';
import { toast } from 'svelte-sonner';
import { v4 as uuidv4 } from 'uuid';
import { onMount, tick, getContext } from 'svelte';
import { onMount, tick, getContext } from 'svelte';
import {
import {
type Model,
type Model,
...
@@ -98,6 +99,8 @@
...
@@ -98,6 +99,8 @@
const uploadFileHandler = async (file) => {
const uploadFileHandler = async (file) => {
console.log(file);
console.log(file);
const fileId = uuidv4();
// Check if the file is an audio file and transcribe/convert it to text file
// Check if the file is an audio file and transcribe/convert it to text file
if (['audio/mpeg', 'audio/wav'].includes(file['type'])) {
if (['audio/mpeg', 'audio/wav'].includes(file['type'])) {
const res = await transcribeAudio(localStorage.token, file).catch((error) => {
const res = await transcribeAudio(localStorage.token, file).catch((error) => {
...
@@ -112,25 +115,27 @@
...
@@ -112,25 +115,27 @@
}
}
}
}
// Upload the file to the server
const uploadedFile = await uploadFile(localStorage.token, file).catch((error) => {
toast.error(error);
return null;
});
if (uploadedFile) {
const fileItem = {
const fileItem = {
type: 'file',
type: 'file',
file:
uploadedFile
,
file:
''
,
id:
uploadedF
ile
.i
d,
id:
f
ile
I
d,
url:
`${WEBUI_API_BASE_URL}/files/${uploadedFile.id}`
,
url:
''
,
name: file.name,
name: file.name,
collection_name: '',
collection_name: '',
status: 'uploaded',
status: 'uploaded',
size: file.size,
error: ''
error: ''
};
};
files = [...files, fileItem];
files = [...files, fileItem];
try {
const uploadedFile = await uploadFile(localStorage.token, file);
if (uploadedFile) {
fileItem.file = uploadedFile;
fileItem.id = uploadedFile.id;
fileItem.url = `${WEBUI_API_BASE_URL}/files/${uploadedFile.id}`;
// TODO: Check if tools & functions have files support to skip this step to delegate file processing
// TODO: Check if tools & functions have files support to skip this step to delegate file processing
// Default Upload to VectorDB
// Default Upload to VectorDB
if (
if (
...
@@ -146,6 +151,12 @@
...
@@ -146,6 +151,12 @@
);
);
processFileItem(fileItem);
processFileItem(fileItem);
}
}
} else {
files = files.filter((item) => item.id !== fileId);
}
} catch (error) {
toast.error(error);
files = files.filter((item) => item.id !== fileId);
}
}
};
};
...
...
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