Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: Fix image-only chat requests failing validation (#5212)
Lee Jacksonff759ba7e4d8
diff --git a/studio/backend/models/inference.py b/studio/backend/models/inference.pyindex bf0177efbfa..eb2bb9c5ceb 100644--- a/studio/backend/models/inference.py+++ b/studio/backend/models/inference.py@@ -396,7 +396,10 @@ class ChatMessage(BaseModel):if self.name is not None and self.role != "tool":raise ValueError('"name" is only valid on role="tool" messages.')- # Per-role content requirements.+ # Per-role content requirements. OpenAI-compatible clients may send+ # ``content=""`` for image-only turns when the image travels in a+ # companion field such as Studio's ``image_base64`` extension, so treat+ # empty strings as present content for user/system messages.if self.role == "tool":if not self.tool_call_id:raise ValueError(@@ -411,10 +414,8 @@ class ChatMessage(BaseModel):'role="assistant" messages require either "content" or "tool_calls".')else: # "user" | "system"- if not self.content:- raise ValueError(- f'role="{self.role}" messages require non-empty "content".'- )+ if self.content is None or self.content == []:+ raise ValueError(f'role="{self.role}" messages require "content".')return selfdiff --git a/studio/backend/tests/test_openai_tool_passthrough.py b/studio/backend/tests/test_openai_tool_passthrough.pyindex ccb0dba325e..cdb7f5d2701 100644--- a/studio/backend/tests/test_openai_tool_passthrough.py+++ b/studio/backend/tests/test_openai_tool_passthrough.py@@ -144,13 +144,14 @@ class TestChatMessageToolRoles:# ── Role-aware content requirements ────────────────────────────- def test_user_empty_content_rejected(self):- with pytest.raises(ValidationError):- ChatMessage(role = "user", content = "")+ @pytest.mark.parametrize("role", ["user", "system"])+ def test_empty_string_content_allowed(self, role):+ msg = ChatMessage(role = role, content = "")+ assert msg.content == ""- def test_system_empty_content_rejected(self):+ def test_user_missing_content_rejected(self):with pytest.raises(ValidationError):- ChatMessage(role = "system", content = "")+ ChatMessage(role = "user")def test_user_empty_list_content_rejected(self):with pytest.raises(ValidationError):@@ -226,6 +227,14 @@ class TestChatCompletionRequestToolFields:assert len(req.tools) == 1assert req.tools[0]["function"]["name"] == "get_weather"+ def test_image_base64_allows_empty_user_text(self):+ req = ChatCompletionRequest(+ messages = [{"role": "user", "content": ""}],+ image_base64 = "aW1hZ2U=",+ )+ assert req.messages[0].content == ""+ assert req.image_base64 == "aW1hZ2U="+def test_tool_choice_string_auto(self):assert self._make(tool_choice = "auto").tool_choice == "auto"