Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
fix(serve): an image_url that is not an object answered 500
kevin93274aa0fc8103cf
diff --git a/c/openai_server.py b/c/openai_server.pyindex 9d595ac9..f5322b27 100644--- a/c/openai_server.py+++ b/c/openai_server.py@@ -1952,6 +1952,21 @@ GLM53_IMAGE_OPEN, GLM53_IMAGE, GLM53_IMAGE_CLOSE = ("<|begin_of_image|>", "<|image|>", "<|end_of_image|>")+def _image_part_url(part, kind):+ """The URL an image content part names. An `image_url` part carries an object,+ `{"url": ...}`, and an `input_image` part the URL itself. `.get("url")` on an+ `image_url` that was a string or a number raised AttributeError, which do_POST+ answers with 500; that is the client's error, so it is a 400 here."""+ value = part.get("image_url")+ if kind != "image_url":+ return value or part.get("url")+ if value is None:+ return None # _image_bytes_from_url answers the missing url+ if not isinstance(value, dict):+ raise APIError(400, "`image_url` must be an object with a `url`.", "messages")+ return value.get("url")++def _image_bytes_from_url(url):"""data: URI, file:// o percorso sul disco -> i byte dell'immagine.@@ -2049,8 +2064,7 @@ def expand_qwen38_images(messages, model_dir, max_tokens=None):if kind == "text":pieces.append(part.get("text", ""))elif kind in ("image_url", "input_image"):- url = (part.get("image_url") or {}).get("url") if kind == "image_url" \- else part.get("image_url") or part.get("url")+ url = _image_part_url(part, kind)data = _image_bytes_from_url(url)patches, grid_h, grid_w = _preprocess_qwen38_image(data, model_dir, max_tokens)@@ -2097,8 +2111,7 @@ def expand_glm53_images(messages, model_dir):if kind == "text":pieces.append(part.get("text", ""))elif kind in ("image_url", "input_image"):- url = (part.get("image_url") or {}).get("url") if kind == "image_url" \- else part.get("image_url") or part.get("url")+ url = _image_part_url(part, kind)data = _image_bytes_from_url(url)patches, grid_h, grid_w = _preprocess_image(data, model_dir)tokens = (grid_h // 2) * (grid_w // 2)@@ -2135,8 +2148,7 @@ def expand_dsv41_images(messages, model_dir, max_tokens=None):if kind == "text":pieces.append(part.get("text", ""))elif kind in ("image_url", "input_image"):- url = (part.get("image_url") or {}).get("url") if kind == "image_url" \- else part.get("image_url") or part.get("url")+ url = _image_part_url(part, kind)data = _image_bytes_from_url(url)patches, grid_h, grid_w, llm_h, llm_w = _preprocess_dsv41_image(data, model_dir, max_tokens)diff --git a/c/tests/test_openai_server.py b/c/tests/test_openai_server.pyindex e6af5a13..13cacdbc 100644--- a/c/tests/test_openai_server.py+++ b/c/tests/test_openai_server.py@@ -273,6 +273,21 @@ class TemplateTest(unittest.TestCase):self.assertEqual(patches.shape[0], grid_h * grid_w)self.assertIn("what is this?", messages[0]["content"])+ def test_an_image_url_that_is_not_an_object_is_a_client_error(self):+ """{"type": "image_url", "image_url": "data:..."} (or a number) made the image+ expanders call .get("url") on a string, an AttributeError that do_POST answered+ with 500 on GLM-5.3, Qwen3.8 and DeepSeek V4.1. It is the client's error: 400."""+ from openai_server import expand_dsv41_images, expand_glm53_images, expand_qwen38_images+ for expand in (expand_glm53_images, expand_qwen38_images, expand_dsv41_images):+ for value in ("data:image/png;base64,AAAA", 5, ["x"]):+ with self.subTest(expand=expand.__name__, value=value):+ with self.assertRaises(APIError) as caught:+ expand([{"role": "user", "content": [+ {"type": "text", "text": "what is this?"},+ {"type": "image_url", "image_url": value}]}], None)+ self.assertEqual(caught.exception.status, 400)+ self.assertIn("`image_url` must be an object", str(caught.exception))+def test_qwen38_template_on_the_qwen36_engine(self):"""#1757: Qwen3.8-27B is a dense model of Qwen3.5's architecture, so the qwen36engine runs it, but it ships Qwen3.8's chat_template.jinja. The gateway renders