From 4e7951d5fc50560e9a58c7b8542c29ff2f000391 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 3 Nov 2024 01:34:45 -0800 Subject: [PATCH] fix: allow openai list message format --- backend/open_webui/apps/ollama/main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/apps/ollama/main.py b/backend/open_webui/apps/ollama/main.py index 2056a4c03..58ceb0d03 100644 --- a/backend/open_webui/apps/ollama/main.py +++ b/backend/open_webui/apps/ollama/main.py @@ -817,7 +817,7 @@ class OpenAIChatMessageContent(BaseModel): class OpenAIChatMessage(BaseModel): role: str - content: Union[str, OpenAIChatMessageContent] + content: Union[str, list[OpenAIChatMessageContent]] model_config = ConfigDict(extra="allow") @@ -836,7 +836,15 @@ async def generate_openai_chat_completion( url_idx: Optional[int] = None, user=Depends(get_verified_user), ): - completion_form = OpenAIChatCompletionForm(**form_data) + try: + completion_form = OpenAIChatCompletionForm(**form_data) + except Exception as e: + log.exception(e) + raise HTTPException( + status_code=400, + detail=str(e), + ) + payload = {**completion_form.model_dump(exclude_none=True, exclude=["metadata"])} if "metadata" in payload: del payload["metadata"]