mirror of
https://github.com/open-webui/open-webui
synced 2025-06-23 02:16:52 +00:00
Feature: adjusted file upload to handle individual rag config (send knowledge base id to get rag config)
This commit is contained in:
parent
49e4375263
commit
8fa985e3ba
@ -15,6 +15,7 @@ from fastapi import (
|
|||||||
UploadFile,
|
UploadFile,
|
||||||
status,
|
status,
|
||||||
Query,
|
Query,
|
||||||
|
Form
|
||||||
)
|
)
|
||||||
from fastapi.responses import FileResponse, StreamingResponse
|
from fastapi.responses import FileResponse, StreamingResponse
|
||||||
from open_webui.constants import ERROR_MESSAGES
|
from open_webui.constants import ERROR_MESSAGES
|
||||||
@ -87,9 +88,10 @@ def upload_file(
|
|||||||
user=Depends(get_verified_user),
|
user=Depends(get_verified_user),
|
||||||
file_metadata: dict = None,
|
file_metadata: dict = None,
|
||||||
process: bool = Query(True),
|
process: bool = Query(True),
|
||||||
|
knowledge_id: Optional[str] = Form(...),
|
||||||
):
|
):
|
||||||
log.info(f"file.content_type: {file.content_type}")
|
log.info(f"file.content_type: {file.content_type}")
|
||||||
|
print("KNOWLEDGE_ID: ", knowledge_id)
|
||||||
file_metadata = file_metadata if file_metadata else {}
|
file_metadata = file_metadata if file_metadata else {}
|
||||||
try:
|
try:
|
||||||
unsanitized_filename = file.filename
|
unsanitized_filename = file.filename
|
||||||
@ -137,6 +139,7 @@ def upload_file(
|
|||||||
process_file(
|
process_file(
|
||||||
request,
|
request,
|
||||||
ProcessFileForm(file_id=id, content=result.get("text", "")),
|
ProcessFileForm(file_id=id, content=result.get("text", "")),
|
||||||
|
knowledge_id= knowledge_id,
|
||||||
user=user,
|
user=user,
|
||||||
)
|
)
|
||||||
elif file.content_type not in [
|
elif file.content_type not in [
|
||||||
@ -148,7 +151,7 @@ def upload_file(
|
|||||||
"video/quicktime",
|
"video/quicktime",
|
||||||
"video/webm",
|
"video/webm",
|
||||||
]:
|
]:
|
||||||
process_file(request, ProcessFileForm(file_id=id), user=user)
|
process_file(request, ProcessFileForm(file_id=id), knowledge_id=knowledge_id, user=user)
|
||||||
|
|
||||||
file_item = Files.get_file_by_id(id=id)
|
file_item = Files.get_file_by_id(id=id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
||||||
|
|
||||||
export const uploadFile = async (token: string, file: File) => {
|
export const uploadFile = async (token: string, file: File, knowledge_id: string) => {
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
data.append('file', file);
|
data.append('file', file);
|
||||||
|
data.append('knowledge_id', knowledge_id);
|
||||||
let error = null;
|
let error = null;
|
||||||
|
|
||||||
const res = await fetch(`${WEBUI_API_BASE_URL}/files/`, {
|
const res = await fetch(`${WEBUI_API_BASE_URL}/files/`, {
|
||||||
|
@ -118,7 +118,7 @@
|
|||||||
return file;
|
return file;
|
||||||
};
|
};
|
||||||
|
|
||||||
const uploadFileHandler = async (file) => {
|
const uploadFileHandler = async (file, knowledgeId) => {
|
||||||
console.log(file);
|
console.log(file);
|
||||||
|
|
||||||
const tempItemId = uuidv4();
|
const tempItemId = uuidv4();
|
||||||
@ -158,7 +158,7 @@
|
|||||||
knowledge.files = [...(knowledge.files ?? []), fileItem];
|
knowledge.files = [...(knowledge.files ?? []), fileItem];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const uploadedFile = await uploadFile(localStorage.token, file).catch((e) => {
|
const uploadedFile = await uploadFile(localStorage.token, file, knowledgeId).catch((e) => {
|
||||||
toast.error(`${e}`);
|
toast.error(`${e}`);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@ -249,7 +249,7 @@
|
|||||||
const file = await entry.getFile();
|
const file = await entry.getFile();
|
||||||
const fileWithPath = new File([file], entryPath, { type: file.type });
|
const fileWithPath = new File([file], entryPath, { type: file.type });
|
||||||
|
|
||||||
await uploadFileHandler(fileWithPath);
|
await uploadFileHandler(fileWithPath, id);
|
||||||
uploadedFiles++;
|
uploadedFiles++;
|
||||||
updateProgress();
|
updateProgress();
|
||||||
} else if (entry.kind === 'directory') {
|
} else if (entry.kind === 'directory') {
|
||||||
@ -311,7 +311,7 @@
|
|||||||
const relativePath = file.webkitRelativePath || file.name;
|
const relativePath = file.webkitRelativePath || file.name;
|
||||||
const fileWithPath = new File([file], relativePath, { type: file.type });
|
const fileWithPath = new File([file], relativePath, { type: file.type });
|
||||||
|
|
||||||
await uploadFileHandler(fileWithPath);
|
await uploadFileHandler(fileWithPath, id);
|
||||||
uploadedFiles++;
|
uploadedFiles++;
|
||||||
updateProgress();
|
updateProgress();
|
||||||
}
|
}
|
||||||
@ -509,7 +509,7 @@
|
|||||||
|
|
||||||
if (inputFiles && inputFiles.length > 0) {
|
if (inputFiles && inputFiles.length > 0) {
|
||||||
for (const file of inputFiles) {
|
for (const file of inputFiles) {
|
||||||
await uploadFileHandler(file);
|
await uploadFileHandler(file, id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
toast.error($i18n.t(`File not found.`));
|
toast.error($i18n.t(`File not found.`));
|
||||||
@ -628,7 +628,7 @@
|
|||||||
bind:show={showAddTextContentModal}
|
bind:show={showAddTextContentModal}
|
||||||
on:submit={(e) => {
|
on:submit={(e) => {
|
||||||
const file = createFileFromText(e.detail.name, e.detail.content);
|
const file = createFileFromText(e.detail.name, e.detail.content);
|
||||||
uploadFileHandler(file);
|
uploadFileHandler(file, id);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@ -641,7 +641,7 @@
|
|||||||
on:change={async () => {
|
on:change={async () => {
|
||||||
if (inputFiles && inputFiles.length > 0) {
|
if (inputFiles && inputFiles.length > 0) {
|
||||||
for (const file of inputFiles) {
|
for (const file of inputFiles) {
|
||||||
await uploadFileHandler(file);
|
await uploadFileHandler(file, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
inputFiles = null;
|
inputFiles = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user