forked from open-webui/open-webui
feat: audio rag support
This commit is contained in:
parent
a5b9bbf10b
commit
c6c69924d1
3 changed files with 24 additions and 5 deletions
|
@ -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 @@
|
||||||
|
|
||||||
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 @@
|
||||||
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))
|
||||||
|
|
|
@ -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 = [
|
||||||
|
|
|
@ -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;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue