diff --git a/backend/open_webui/apps/retrieval/main.py b/backend/open_webui/apps/retrieval/main.py index d54cc8f4a..04eece38c 100644 --- a/backend/open_webui/apps/retrieval/main.py +++ b/backend/open_webui/apps/retrieval/main.py @@ -16,8 +16,8 @@ from fastapi.middleware.cors import CORSMiddleware from pydantic import BaseModel +from open_webui.storage.provider import Storage from open_webui.apps.webui.models.knowledge import Knowledges - from open_webui.apps.retrieval.vector.connector import VECTOR_DB_CLIENT # Document loaders @@ -824,15 +824,14 @@ def process_file( else: # Process the file and save the content # Usage: /files/ - file_path = file.path if file_path: + file_path = Storage.get_file(file_path) loader = Loader( engine=app.state.config.CONTENT_EXTRACTION_ENGINE, TIKA_SERVER_URL=app.state.config.TIKA_SERVER_URL, PDF_EXTRACT_IMAGES=app.state.config.PDF_EXTRACT_IMAGES, ) - docs = loader.load( file.filename, file.meta.get("content_type"), file_path ) @@ -848,7 +847,6 @@ def process_file( }, ) ] - text_content = " ".join([doc.page_content for doc in docs]) log.debug(f"text_content: {text_content}") diff --git a/backend/open_webui/apps/webui/routers/files.py b/backend/open_webui/apps/webui/routers/files.py index d3a117a9c..0a3f22df8 100644 --- a/backend/open_webui/apps/webui/routers/files.py +++ b/backend/open_webui/apps/webui/routers/files.py @@ -51,7 +51,7 @@ def upload_file(file: UploadFile = File(...), user=Depends(get_verified_user)): filename = f"{id}_{filename}" contents, file_path = Storage.upload_file(file.file, filename) - file = Files.insert_new_file( + file_item = Files.insert_new_file( user.id, FileForm( **{ @@ -72,10 +72,10 @@ def upload_file(file: UploadFile = File(...), user=Depends(get_verified_user)): file = Files.get_file_by_id(id=id) except Exception as e: log.exception(e) - log.error(f"Error processing file: {file.id}") + log.error(f"Error processing file: {file_item.id}") - if file: - return file + if file_item: + return file_item else: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST,