mirror of
https://github.com/open-webui/open-webui
synced 2024-11-22 08:07:55 +00:00
refac
This commit is contained in:
parent
7984980619
commit
e43e91edd3
@ -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}")
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user