mirror of
https://github.com/open-webui/open-webui
synced 2025-05-15 02:56:09 +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 pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
from open_webui.storage.provider import Storage
|
||||||
from open_webui.apps.webui.models.knowledge import Knowledges
|
from open_webui.apps.webui.models.knowledge import Knowledges
|
||||||
|
|
||||||
from open_webui.apps.retrieval.vector.connector import VECTOR_DB_CLIENT
|
from open_webui.apps.retrieval.vector.connector import VECTOR_DB_CLIENT
|
||||||
|
|
||||||
# Document loaders
|
# Document loaders
|
||||||
@ -824,15 +824,14 @@ def process_file(
|
|||||||
else:
|
else:
|
||||||
# Process the file and save the content
|
# Process the file and save the content
|
||||||
# Usage: /files/
|
# Usage: /files/
|
||||||
|
|
||||||
file_path = file.path
|
file_path = file.path
|
||||||
if file_path:
|
if file_path:
|
||||||
|
file_path = Storage.get_file(file_path)
|
||||||
loader = Loader(
|
loader = Loader(
|
||||||
engine=app.state.config.CONTENT_EXTRACTION_ENGINE,
|
engine=app.state.config.CONTENT_EXTRACTION_ENGINE,
|
||||||
TIKA_SERVER_URL=app.state.config.TIKA_SERVER_URL,
|
TIKA_SERVER_URL=app.state.config.TIKA_SERVER_URL,
|
||||||
PDF_EXTRACT_IMAGES=app.state.config.PDF_EXTRACT_IMAGES,
|
PDF_EXTRACT_IMAGES=app.state.config.PDF_EXTRACT_IMAGES,
|
||||||
)
|
)
|
||||||
|
|
||||||
docs = loader.load(
|
docs = loader.load(
|
||||||
file.filename, file.meta.get("content_type"), file_path
|
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])
|
text_content = " ".join([doc.page_content for doc in docs])
|
||||||
|
|
||||||
log.debug(f"text_content: {text_content}")
|
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}"
|
filename = f"{id}_{filename}"
|
||||||
contents, file_path = Storage.upload_file(file.file, filename)
|
contents, file_path = Storage.upload_file(file.file, filename)
|
||||||
|
|
||||||
file = Files.insert_new_file(
|
file_item = Files.insert_new_file(
|
||||||
user.id,
|
user.id,
|
||||||
FileForm(
|
FileForm(
|
||||||
**{
|
**{
|
||||||
@ -72,10 +72,10 @@ def upload_file(file: UploadFile = File(...), user=Depends(get_verified_user)):
|
|||||||
file = Files.get_file_by_id(id=id)
|
file = Files.get_file_by_id(id=id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
log.error(f"Error processing file: {file.id}")
|
log.error(f"Error processing file: {file_item.id}")
|
||||||
|
|
||||||
if file:
|
if file_item:
|
||||||
return file
|
return file_item
|
||||||
else:
|
else:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
Loading…
Reference in New Issue
Block a user