From 2c87472483ff2a6f1c72d310a0249497834fccc1 Mon Sep 17 00:00:00 2001 From: alpha nerd Date: Tue, 7 Apr 2026 13:28:34 +0200 Subject: [PATCH] fix: conditional to_thread for the image_transform to relieve threadpool pressure --- router.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/router.py b/router.py index 08a2e18..94cf1c2 100644 --- a/router.py +++ b/router.py @@ -1059,7 +1059,8 @@ async def _make_chat_request(model: str, messages: list, tools=None, stream: boo if ":latest" in model: model = model.split(":latest")[0] if messages: - messages = await asyncio.to_thread(transform_images_to_data_urls, messages) + if any("images" in m for m in messages): + messages = await asyncio.to_thread(transform_images_to_data_urls, messages) messages = transform_tool_calls_to_openai(messages) messages = _strip_assistant_prefill(messages) params = { @@ -1965,7 +1966,8 @@ async def chat_proxy(request: Request): model = model.split(":latest") model = model[0] if messages: - messages = await asyncio.to_thread(transform_images_to_data_urls, messages) + if any("images" in m for m in messages): + messages = await asyncio.to_thread(transform_images_to_data_urls, messages) messages = transform_tool_calls_to_openai(messages) messages = _strip_assistant_prefill(messages) params = {