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,
|
||||
status,
|
||||
Query,
|
||||
Form
|
||||
)
|
||||
from fastapi.responses import FileResponse, StreamingResponse
|
||||
from open_webui.constants import ERROR_MESSAGES
|
||||
@ -87,9 +88,10 @@ def upload_file(
|
||||
user=Depends(get_verified_user),
|
||||
file_metadata: dict = None,
|
||||
process: bool = Query(True),
|
||||
knowledge_id: Optional[str] = Form(...),
|
||||
):
|
||||
log.info(f"file.content_type: {file.content_type}")
|
||||
|
||||
print("KNOWLEDGE_ID: ", knowledge_id)
|
||||
file_metadata = file_metadata if file_metadata else {}
|
||||
try:
|
||||
unsanitized_filename = file.filename
|
||||
@ -137,6 +139,7 @@ def upload_file(
|
||||
process_file(
|
||||
request,
|
||||
ProcessFileForm(file_id=id, content=result.get("text", "")),
|
||||
knowledge_id= knowledge_id,
|
||||
user=user,
|
||||
)
|
||||
elif file.content_type not in [
|
||||
@ -148,7 +151,7 @@ def upload_file(
|
||||
"video/quicktime",
|
||||
"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)
|
||||
except Exception as e:
|
||||
|
@ -1,8 +1,9 @@
|
||||
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();
|
||||
data.append('file', file);
|
||||
data.append('knowledge_id', knowledge_id);
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/files/`, {
|
||||
|
@ -118,7 +118,7 @@
|
||||
return file;
|
||||
};
|
||||
|
||||
const uploadFileHandler = async (file) => {
|
||||
const uploadFileHandler = async (file, knowledgeId) => {
|
||||
console.log(file);
|
||||
|
||||
const tempItemId = uuidv4();
|
||||
@ -158,7 +158,7 @@
|
||||
knowledge.files = [...(knowledge.files ?? []), fileItem];
|
||||
|
||||
try {
|
||||
const uploadedFile = await uploadFile(localStorage.token, file).catch((e) => {
|
||||
const uploadedFile = await uploadFile(localStorage.token, file, knowledgeId).catch((e) => {
|
||||
toast.error(`${e}`);
|
||||
return null;
|
||||
});
|
||||
@ -249,7 +249,7 @@
|
||||
const file = await entry.getFile();
|
||||
const fileWithPath = new File([file], entryPath, { type: file.type });
|
||||
|
||||
await uploadFileHandler(fileWithPath);
|
||||
await uploadFileHandler(fileWithPath, id);
|
||||
uploadedFiles++;
|
||||
updateProgress();
|
||||
} else if (entry.kind === 'directory') {
|
||||
@ -311,7 +311,7 @@
|
||||
const relativePath = file.webkitRelativePath || file.name;
|
||||
const fileWithPath = new File([file], relativePath, { type: file.type });
|
||||
|
||||
await uploadFileHandler(fileWithPath);
|
||||
await uploadFileHandler(fileWithPath, id);
|
||||
uploadedFiles++;
|
||||
updateProgress();
|
||||
}
|
||||
@ -509,7 +509,7 @@
|
||||
|
||||
if (inputFiles && inputFiles.length > 0) {
|
||||
for (const file of inputFiles) {
|
||||
await uploadFileHandler(file);
|
||||
await uploadFileHandler(file, id);
|
||||
}
|
||||
} else {
|
||||
toast.error($i18n.t(`File not found.`));
|
||||
@ -628,7 +628,7 @@
|
||||
bind:show={showAddTextContentModal}
|
||||
on:submit={(e) => {
|
||||
const file = createFileFromText(e.detail.name, e.detail.content);
|
||||
uploadFileHandler(file);
|
||||
uploadFileHandler(file, id);
|
||||
}}
|
||||
/>
|
||||
|
||||
@ -641,7 +641,7 @@
|
||||
on:change={async () => {
|
||||
if (inputFiles && inputFiles.length > 0) {
|
||||
for (const file of inputFiles) {
|
||||
await uploadFileHandler(file);
|
||||
await uploadFileHandler(file, id);
|
||||
}
|
||||
|
||||
inputFiles = null;
|
||||
|
Loading…
Reference in New Issue
Block a user