From aefb3117db8d02fd8f19ea6c8d1821cc708e96c8 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 6 Apr 2025 23:40:48 -0700 Subject: [PATCH] fix: chat completion non-existent model issue --- backend/open_webui/main.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index c9ca059c2..8e7d6a8be 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -1108,13 +1108,15 @@ async def chat_completion( except Exception as e: log.debug(f"Error processing chat payload: {e}") - Chats.upsert_message_to_chat_by_id_and_message_id( - metadata["chat_id"], - metadata["message_id"], - { - "error": {"content": str(e)}, - }, - ) + if metadata.get("chat_id") and metadata.get("message_id"): + # Update the chat message with the error + Chats.upsert_message_to_chat_by_id_and_message_id( + metadata["chat_id"], + metadata["message_id"], + { + "error": {"content": str(e)}, + }, + ) raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST,