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
c6c69924
Commit
c6c69924
authored
Feb 11, 2024
by
Timothy J. Baek
Browse files
feat: audio rag support
parent
a5b9bbf1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
5 deletions
+24
-5
src/lib/components/chat/MessageInput.svelte
src/lib/components/chat/MessageInput.svelte
+15
-4
src/lib/constants.ts
src/lib/constants.ts
+3
-1
src/lib/utils/index.ts
src/lib/utils/index.ts
+6
-0
No files found.
src/lib/components/chat/MessageInput.svelte
View file @
c6c69924
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import toast from 'svelte-french-toast';
import toast from 'svelte-french-toast';
import { onMount, tick } from 'svelte';
import { onMount, tick } from 'svelte';
import { settings } from '$lib/stores';
import { settings } from '$lib/stores';
import { calculateSHA256, findWordIndices } from '$lib/utils';
import {
blobToFile,
calculateSHA256, findWordIndices } from '$lib/utils';
import Prompts from './MessageInput/PromptCommands.svelte';
import Prompts from './MessageInput/PromptCommands.svelte';
import Suggestions from './MessageInput/Suggestions.svelte';
import Suggestions from './MessageInput/Suggestions.svelte';
...
@@ -124,6 +124,20 @@
...
@@ -124,6 +124,20 @@
try {
try {
files = [...files, doc];
files = [...files, doc];
if (['audio/mpeg', 'audio/wav'].includes(file['type'])) {
const res = await transcribeAudio(localStorage.token, file).catch((error) => {
toast.error(error);
return null;
});
if (res) {
console.log(res);
const blob = new Blob([res.text], { type: 'text/plain' });
file = blobToFile(blob, `${file.name}.txt`);
}
}
const res = await uploadDocToVectorDB(localStorage.token, '', file);
const res = await uploadDocToVectorDB(localStorage.token, '', file);
if (res) {
if (res) {
...
@@ -202,9 +216,6 @@
...
@@ -202,9 +216,6 @@
console.log(file, file.name.split('.').at(-1));
console.log(file, file.name.split('.').at(-1));
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 (['audio/mpeg', 'audio/wav'].includes(file['type'])) {
const res = await transcribeAudio(localStorage.token, file);
console.log(res);
} else if (
} else if (
SUPPORTED_FILE_TYPE.includes(file['type']) ||
SUPPORTED_FILE_TYPE.includes(file['type']) ||
SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1))
SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1))
...
...
src/lib/constants.ts
View file @
c6c69924
...
@@ -24,7 +24,9 @@ export const SUPPORTED_FILE_TYPE = [
...
@@ -24,7 +24,9 @@ export const SUPPORTED_FILE_TYPE = [
'
application/vnd.openxmlformats-officedocument.wordprocessingml.document
'
,
'
application/vnd.openxmlformats-officedocument.wordprocessingml.document
'
,
'
application/octet-stream
'
,
'
application/octet-stream
'
,
'
application/x-javascript
'
,
'
application/x-javascript
'
,
'
text/markdown
'
'
text/markdown
'
,
'
audio/mpeg
'
,
'
audio/wav
'
];
];
export
const
SUPPORTED_FILE_EXTENSIONS
=
[
export
const
SUPPORTED_FILE_EXTENSIONS
=
[
...
...
src/lib/utils/index.ts
View file @
c6c69924
...
@@ -341,3 +341,9 @@ export const extractSentences = (text) => {
...
@@ -341,3 +341,9 @@ export const extractSentences = (text) => {
.
map
((
sentence
)
=>
removeEmojis
(
sentence
.
trim
()))
.
map
((
sentence
)
=>
removeEmojis
(
sentence
.
trim
()))
.
filter
((
sentence
)
=>
sentence
!==
''
);
.
filter
((
sentence
)
=>
sentence
!==
''
);
};
};
export
const
blobToFile
=
(
blob
,
fileName
)
=>
{
// Create a new File object from the Blob
const
file
=
new
File
([
blob
],
fileName
,
{
type
:
blob
.
type
});
return
file
;
};
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