Feature: adjusted file upload to handle individual rag config (send knowledge base id to get rag config)

This commit is contained in:
Maytown
2025-05-06 12:53:24 +02:00
parent 49e4375263
commit 8fa985e3ba
3 changed files with 14 additions and 10 deletions

View File

@@ -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/`, {

View File

@@ -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;