From 16d900247a4c12e4f916b0c531f37e9dafa095ee Mon Sep 17 00:00:00 2001 From: envision3d Date: Tue, 17 Dec 2024 09:33:32 -0600 Subject: [PATCH] feat: pass structured output format through to ollama --- backend/open_webui/routers/ollama.py | 2 +- backend/open_webui/utils/payload.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/routers/ollama.py b/backend/open_webui/routers/ollama.py index 233e30ce5..0c152c1f0 100644 --- a/backend/open_webui/routers/ollama.py +++ b/backend/open_webui/routers/ollama.py @@ -917,7 +917,7 @@ class ChatMessage(BaseModel): class GenerateChatCompletionForm(BaseModel): model: str messages: list[ChatMessage] - format: Optional[str] = None + format: Optional[dict] = None options: Optional[dict] = None template: Optional[str] = None stream: Optional[bool] = True diff --git a/backend/open_webui/utils/payload.py b/backend/open_webui/utils/payload.py index 04e3a98c4..0125a799c 100644 --- a/backend/open_webui/utils/payload.py +++ b/backend/open_webui/utils/payload.py @@ -154,6 +154,9 @@ def convert_payload_openai_to_ollama(openai_payload: dict) -> dict: ) ollama_payload["stream"] = openai_payload.get("stream", False) + if "format" in openai_payload: + ollama_payload["format"] = openai_payload["format"] + # If there are advanced parameters in the payload, format them in Ollama's options field ollama_options = {}