From 5e720cd84b4886594eac1ef8ac25cb61a4def85d Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 27 Mar 2025 19:26:08 -0700 Subject: [PATCH] refac: ollama response_format support --- backend/open_webui/utils/payload.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/open_webui/utils/payload.py b/backend/open_webui/utils/payload.py index 14fae4589..452209491 100644 --- a/backend/open_webui/utils/payload.py +++ b/backend/open_webui/utils/payload.py @@ -63,6 +63,7 @@ def apply_model_params_to_body_openai(params: dict, form_data: dict) -> dict: "seed": lambda x: x, "stop": lambda x: [bytes(s, "utf-8").decode("unicode_escape") for s in x], "logit_bias": lambda x: x, + "response_format": dict, } return apply_model_params_to_body(params, form_data, mappings) @@ -250,4 +251,13 @@ def convert_payload_openai_to_ollama(openai_payload: dict) -> dict: if "metadata" in openai_payload: ollama_payload["metadata"] = openai_payload["metadata"] + if "response_format" in openai_payload: + response_format = openai_payload["response_format"] + format_type = response_format.get("type", None) + + schema = response_format.get(format_type, None) + if schema: + format = schema.get("schema", None) + ollama_payload["format"] = format + return ollama_payload