From a0fb4a9b848f0100e72f825353fbccb14550dcfa Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 1 Oct 2024 13:13:39 -0700 Subject: [PATCH] refac --- backend/open_webui/apps/retrieval/main.py | 8 ++------ backend/open_webui/apps/webui/models/files.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/open_webui/apps/retrieval/main.py b/backend/open_webui/apps/retrieval/main.py index 2a79ac90f..4d280193f 100644 --- a/backend/open_webui/apps/retrieval/main.py +++ b/backend/open_webui/apps/retrieval/main.py @@ -729,13 +729,9 @@ def process_file( text_content = " ".join([doc.page_content for doc in docs]) log.debug(f"text_content: {text_content}") - Files.update_files_metadata_by_id( + Files.update_files_data_by_id( form_data.file_id, - { - "content": { - "text": text_content, - } - }, + {"content": text_content}, ) try: diff --git a/backend/open_webui/apps/webui/models/files.py b/backend/open_webui/apps/webui/models/files.py index f1262d5dd..dcb98c20b 100644 --- a/backend/open_webui/apps/webui/models/files.py +++ b/backend/open_webui/apps/webui/models/files.py @@ -112,6 +112,17 @@ class FilesTable: for file in db.query(File).filter_by(user_id=user_id).all() ] + def update_files_data_by_id(self, id: str, data: dict) -> Optional[FileModel]: + with get_db() as db: + try: + file = db.query(File).filter_by(id=id).first() + file.data = {**file.data, **data} + db.commit() + + return FileModel.model_validate(file) + except Exception: + return None + def update_files_metadata_by_id(self, id: str, meta: dict) -> Optional[FileModel]: with get_db() as db: try: