From eabdd4a14059881b4a569dbb72e145d2b5e89a25 Mon Sep 17 00:00:00 2001 From: Athanasios Oikonomou Date: Sun, 18 May 2025 22:44:51 +0300 Subject: [PATCH] feat: read max_tokens from model config with fallback to 1000 for title and tag generation Improves title and tag generation by using the max_tokens value from the model configuration when available, with a fallback to the previous default of 1000. This change is necessary for models like Gemini Pro that generate longer responses and require a higher token limit to successfully generate titles or tags. --- backend/open_webui/routers/tasks.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/routers/tasks.py b/backend/open_webui/routers/tasks.py index 8b34c8630..f94346099 100644 --- a/backend/open_webui/routers/tasks.py +++ b/backend/open_webui/routers/tasks.py @@ -192,15 +192,19 @@ async def generate_title( }, ) + max_tokens = ( + models[task_model_id].get("info", {}).get("params", {}).get("max_tokens", 1000) + ) + payload = { "model": task_model_id, "messages": [{"role": "user", "content": content}], "stream": False, **( - {"max_tokens": 1000} + {"max_tokens": max_tokens} if models[task_model_id].get("owned_by") == "ollama" else { - "max_completion_tokens": 1000, + "max_completion_tokens": max_tokens, } ), "metadata": {