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: open a pasted-text upload without its <pasted_text> wrapper (#12198)
Mohammad Hijjawi3de9fce71648
diff --git a/studio/backend/routes/chat_history.py b/studio/backend/routes/chat_history.pyindex 0cc01bbc9d4..986a431b6a2 100644--- a/studio/backend/routes/chat_history.py+++ b/studio/backend/routes/chat_history.py@@ -992,7 +992,8 @@ def _decode_attachment_base64(payload: str) -> bytes:raise HTTPException(status_code = 422, detail = "Attachment data is corrupt") from exc-_ATTACHMENT_TAG_RE = re.compile(r"<attachment name=[^\n]*>\n(.*)\n</attachment>", re.DOTALL)+# A long paste is attached as text under its own tag (attachmentContentText in pasted-text.ts).+_ATTACHMENT_TAG_RE = re.compile(r"<(attachment|pasted_text) name=[^\n]*>\n(.*)\n</\1>", re.DOTALL)_ATTACHMENT_LABEL_RE = re.compile(r"\[(?:PDF|DOCX|HTML|ODS|ODT|XLSX|PPTX|RTF): [^\n]*\]\n")@@ -1000,7 +1001,7 @@ def _attachment_body_text(text: str) -> str:"""An attachment's text without its chat wrapper, as the file itself reads."""tagged = _ATTACHMENT_TAG_RE.fullmatch(text)if tagged:- return tagged.group(1)+ return tagged.group(2)labelled = _ATTACHMENT_LABEL_RE.match(text)return text[labelled.end() :] if labelled else textdiff --git a/studio/backend/tests/test_chat_attachments.py b/studio/backend/tests/test_chat_attachments.pyindex fa4450e3421..3e2621d3ed3 100644--- a/studio/backend/tests/test_chat_attachments.py+++ b/studio/backend/tests/test_chat_attachments.py@@ -375,6 +375,23 @@ def test_attachment_file_serves_text_parts(tmp_path, monkeypatch):assert response.media_type.startswith("text/plain")+def test_attachment_file_unwraps_a_pasted_text_attachment(tmp_path, monkeypatch):+ attachment = {+ "id": "att-paste",+ "type": "document",+ "name": "Pasted text",+ "content": [+ {+ "type": "text",+ "text": "<pasted_text name=Pasted text bytes=11>\nhello\nworld\n</pasted_text>",+ }+ ],+ }+ _seed(tmp_path, monkeypatch, [attachment])+ response = chat_history.get_attachment_file("msg-1", "att-paste", current_subject = "unsloth")+ assert response.body.decode("utf-8") == "hello\nworld"++def test_attachment_file_no_content_is_404(tmp_path, monkeypatch):_seed(tmp_path, monkeypatch, [{"id": "att-empty", "name": "ghost", "content": []}])with pytest.raises(HTTPException) as excinfo: