From 15cfdc69a85fc63f1d6c3f6449c7b07ac7fb44f6 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 26 Oct 2024 12:56:37 -0700 Subject: [PATCH] refac: chat input file handling --- backend/open_webui/apps/webui/models/files.py | 2 ++ backend/open_webui/apps/webui/routers/files.py | 8 +++++++- src/lib/components/chat/MessageInput.svelte | 17 +++++++++++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/open_webui/apps/webui/models/files.py b/backend/open_webui/apps/webui/models/files.py index 5e5fbaadb..31c9164b6 100644 --- a/backend/open_webui/apps/webui/models/files.py +++ b/backend/open_webui/apps/webui/models/files.py @@ -73,6 +73,8 @@ class FileModelResponse(BaseModel): created_at: int # timestamp in epoch updated_at: int # timestamp in epoch + model_config = ConfigDict(extra="allow") + class FileMetadataResponse(BaseModel): id: str diff --git a/backend/open_webui/apps/webui/routers/files.py b/backend/open_webui/apps/webui/routers/files.py index 5e316fa12..551b6d788 100644 --- a/backend/open_webui/apps/webui/routers/files.py +++ b/backend/open_webui/apps/webui/routers/files.py @@ -38,7 +38,7 @@ router = APIRouter() ############################ -@router.post("/") +@router.post("/", response_model=FileModelResponse) def upload_file(file: UploadFile = File(...), user=Depends(get_verified_user)): log.info(f"file.content_type: {file.content_type}") try: @@ -73,6 +73,12 @@ def upload_file(file: UploadFile = File(...), user=Depends(get_verified_user)): except Exception as e: log.exception(e) log.error(f"Error processing file: {file_item.id}") + file_item = FileModelResponse( + **{ + **file_item.model_dump(), + "error": e, + } + ) if file_item: return file_item diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index ce48d9dfb..49a08176b 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -1,5 +1,7 @@