Browse Source

fix: chat completion non-existent model issue

Timothy Jaeryang Baek 2 months ago
parent
commit
aefb3117db
1 changed files with 9 additions and 7 deletions
  1. 9 7
      backend/open_webui/main.py

+ 9 - 7
backend/open_webui/main.py

@@ -1108,13 +1108,15 @@ async def chat_completion(
 
 
     except Exception as e:
     except Exception as e:
         log.debug(f"Error processing chat payload: {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(
         raise HTTPException(
             status_code=status.HTTP_400_BAD_REQUEST,
             status_code=status.HTTP_400_BAD_REQUEST,