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: stop showing a stray </think> after an OpenAI model calls a tool (#17455)
Nilay13a92a320e03
diff --git a/studio/backend/core/inference/external_provider.py b/studio/backend/core/inference/external_provider.pyindex a0969c9575c..563828aeab9 100644--- a/studio/backend/core/inference/external_provider.py+++ b/studio/backend/core/inference/external_provider.py@@ -6702,6 +6702,9 @@ class ExternalProviderClient:):raw_item_id = item.get("id")if isinstance(raw_item_id, str) and raw_item_id:+ if reasoning_open:+ yield _chunk_with_text("</think>")+ reasoning_open = Falsearguments = _image_generation_arguments("",raw_item_id,@@ -6720,6 +6723,9 @@ class ExternalProviderClient:item = event.get("item", {})if not isinstance(item, dict):continue+ if reasoning_open and item.get("type") != "reasoning":+ yield _chunk_with_text("</think>")+ reasoning_open = Falseif item.get("type") == "reasoning":last_openai_reasoning_replay_item = (_record_openai_reasoning_replay_item(item)diff --git a/studio/backend/tests/test_openai_responses_translation.py b/studio/backend/tests/test_openai_responses_translation.pyindex 8ce3733dd7b..b8fcea2c8d3 100644--- a/studio/backend/tests/test_openai_responses_translation.py+++ b/studio/backend/tests/test_openai_responses_translation.py@@ -937,6 +937,80 @@ def test_responses_streamed_reasoning_summary_shown_once(monkeypatch, with_deltaassert combined == "<think>Thinking about it.\n\nThen answering.</think>Hello"+ "tool_item",+ (+ {+ "type": "function_call",+ "id": "fc_1",+ "call_id": "call_1",+ "name": "web_search",+ "arguments": '{"query":"unsloth"}',+ },+ {+ "type": "web_search_call",+ "id": "ws_1",+ "action": {"type": "search", "query": "unsloth"},+ },+ {"type": "shell_call", "id": "sh_1", "action": {"commands": ["ls"]}},+ {"type": "image_generation_call", "id": "ig_1", "result": ""},+ ),+ ids = lambda item: item["type"],+)+def test_responses_think_block_closes_before_tool_call(monkeypatch, tool_item):+ def handler(request: httpx.Request) -> httpx.Response:+ base = {"item_id": "rs_1", "output_index": 0, "summary_index": 0}+ events = [+ {+ "type": "response.output_item.added",+ "output_index": 0,+ "item": {"type": "reasoning", "id": "rs_1", "summary": []},+ },+ {"type": "response.reasoning_summary_text.delta", **base, "delta": "Planning "},+ {"type": "response.reasoning_summary_text.delta", **base, "delta": "a tool call."},+ {+ "type": "response.output_item.done",+ "output_index": 0,+ "item": {+ "type": "reasoning",+ "id": "rs_1",+ "summary": [{"type": "summary_text", "text": "Planning a tool call."}],+ },+ },+ {"type": "response.output_item.added", "output_index": 1, "item": tool_item},+ {"type": "response.output_item.done", "output_index": 1, "item": tool_item},+ {"type": "response.completed", "response": {}},+ ]+ return httpx.Response(+ 200,+ content = _responses_sse(events),+ headers = {"content-type": "text/event-stream"},+ )++ _mock_http_client(monkeypatch, handler)++ lines = _drive(run())+ payloads = [+ json.loads(line[len("data:") :].strip())+ for line in lines+ if line.startswith("data:") and line[len("data:") :].strip() not in ("", "[DONE]")+ ]+ tool_at = next(+ i+ for i, payload in enumerate(payloads)+ if payload.get("_toolEvent")+ or (payload["choices"] and payload["choices"][0]["delta"].get("tool_calls"))+ )++ def text(chunks: list[dict]) -> str:+ return "".join(+ chunk["choices"][0]["delta"].get("content", "") for chunk in chunks if chunk["choices"]+ )++ assert text(payloads[:tool_at]) == "<think>Planning a tool call.</think>"+ assert text(payloads[tool_at:]) == ""++@pytest.mark.parametrize(("body", "expected"),(