This commit is contained in:
Timothy J. Baek 2024-10-20 23:45:15 -07:00
parent 7984980619
commit e43e91edd3
2 changed files with 6 additions and 8 deletions

View File

@ -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}")

View File

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