From e35883ca9c01f2309924a4c430e02c3868c27b57 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 21 Sep 2024 21:35:00 +0200 Subject: [PATCH] fix: openai payload issue --- backend/open_webui/apps/openai/main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/apps/openai/main.py b/backend/open_webui/apps/openai/main.py index 87bcc042c..93155063f 100644 --- a/backend/open_webui/apps/openai/main.py +++ b/backend/open_webui/apps/openai/main.py @@ -411,7 +411,12 @@ async def generate_chat_completion( # Change max_completion_tokens to max_tokens (Backward compatible) if "api.openai.com" not in url and not payload["model"].lower().startswith("o1-"): if "max_completion_tokens" in payload: - payload["max_tokens"] = payload.pop("max_completion_tokens") + # Remove "max_completion_tokens" from the payload + payload["max_tokens"] = payload["max_completion_tokens"] + del payload["max_completion_tokens"] + else: + if "max_tokens" in payload and "max_completion_tokens" in payload: + del payload["max_tokens"] # Convert the modified body back to JSON payload = json.dumps(payload)