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
039c5c54
Unverified
Commit
039c5c54
authored
Aug 01, 2024
by
Timothy Jaeryang Baek
Committed by
GitHub
Aug 01, 2024
Browse files
Merge pull request #4225 from Yanyutin753/pref_file_upload
⚡
Initialize fileItem first to speed up file display
parents
ef36b216
c9ed934d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
33 deletions
+42
-33
src/lib/components/chat/MessageInput.svelte
src/lib/components/chat/MessageInput.svelte
+42
-33
No files found.
src/lib/components/chat/MessageInput.svelte
View file @
039c5c54
...
@@ -98,6 +98,7 @@
...
@@ -98,6 +98,7 @@
const uploadFileHandler = async (file) => {
const uploadFileHandler = async (file) => {
console.log(file);
console.log(file);
// 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,40 +113,49 @@
...
@@ -112,40 +113,49 @@
}
}
}
}
// Upload the file to the server
const fileItem = {
const uploadedFile = await uploadFile(localStorage.token, file).catch((error) => {
type: 'file',
toast.error(error);
file: '',
return null;
id: null,
});
url: '',
name: file.name,
if (uploadedFile) {
collection_name: '',
const fileItem = {
status: '',
type: 'file',
size: file.size,
file: uploadedFile,
error: ''
id: uploadedFile.id,
};
url: `${WEBUI_API_BASE_URL}/files/${uploadedFile.id}`,
files = [...files, fileItem];
name: file.name,
collection_name: '',
try {
status: 'uploaded',
const uploadedFile = await uploadFile(localStorage.token, file);
error: ''
};
if (uploadedFile) {
files = [...files, fileItem];
fileItem.status = 'uploaded';
fileItem.file = uploadedFile;
// TODO: Check if tools & functions have files support to skip this step to delegate file processing
fileItem.id = uploadedFile.id;
// Default Upload to VectorDB
fileItem.url = `${WEBUI_API_BASE_URL}/files/${uploadedFile.id}`;
if (
SUPPORTED_FILE_TYPE.includes(file['type']) ||
// TODO: Check if tools & functions have files support to skip this step to delegate file processing
SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1))
// Default Upload to VectorDB
) {
if (
processFileItem(fileItem);
SUPPORTED_FILE_TYPE.includes(file['type']) ||
SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1))
) {
processFileItem(fileItem);
} else {
toast.error(
$i18n.t(`Unknown file type '{{file_type}}'. Proceeding with the file upload anyway.`, {
file_type: file['type']
})
);
processFileItem(fileItem);
}
} else {
} else {
toast.error(
files = files.filter((item) => item.status !== null);
$i18n.t(`Unknown file type '{{file_type}}'. Proceeding with the file upload anyway.`, {
file_type: file['type']
})
);
processFileItem(fileItem);
}
}
} catch (e) {
toast.error(e);
files = files.filter((item) => item.status !== null);
}
}
};
};
...
@@ -162,7 +172,6 @@
...
@@ -162,7 +172,6 @@
// Remove the failed doc from the files array
// Remove the failed doc from the files array
// files = files.filter((f) => f.id !== fileItem.id);
// files = files.filter((f) => f.id !== fileItem.id);
toast.error(e);
toast.error(e);
fileItem.status = 'processed';
fileItem.status = 'processed';
files = files;
files = files;
}
}
...
...
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