From e1ea0c23ebb4a5d35b9406d21bc4fe747c344705 Mon Sep 17 00:00:00 2001 From: kivvi Date: Sat, 21 Sep 2024 09:06:28 +0800 Subject: [PATCH] Fixed the issue of being unable to generate titles --- backend/open_webui/apps/openai/main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/apps/openai/main.py b/backend/open_webui/apps/openai/main.py index 9a27c46a3..87bcc042c 100644 --- a/backend/open_webui/apps/openai/main.py +++ b/backend/open_webui/apps/openai/main.py @@ -405,14 +405,19 @@ async def generate_chat_completion( "role": user.role, } + url = app.state.config.OPENAI_API_BASE_URLS[idx] + key = app.state.config.OPENAI_API_KEYS[idx] + + # 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") + # Convert the modified body back to JSON payload = json.dumps(payload) log.debug(payload) - url = app.state.config.OPENAI_API_BASE_URLS[idx] - key = app.state.config.OPENAI_API_KEYS[idx] - headers = {} headers["Authorization"] = f"Bearer {key}" headers["Content-Type"] = "application/json"