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: preserve refusal messages in imported chats (#16599)
DimitriChrysafis91be10960820
diff --git a/studio/frontend/src/features/chat/utils/chat-import.ts b/studio/frontend/src/features/chat/utils/chat-import.tsindex 0fcda9cebbe..8cd1d271d46 100644--- a/studio/frontend/src/features/chat/utils/chat-import.ts+++ b/studio/frontend/src/features/chat/utils/chat-import.ts@@ -119,6 +119,9 @@ function oaiContentToParts(raw: unknown): unknown[] {if (part.type === "text" && typeof part.text === "string") {return [{ type: "text", text: part.text }];}+ if (part.type === "refusal" && typeof part.refusal === "string") {+ return [{ type: "text", text: part.refusal }];+ }if (part.type === "image_url") {const imageUrl =typeof part.image_url === "object" && part.image_url !== null@@ -169,6 +172,7 @@ function oaiMessagesToRecords(if (role === "assistant") {const parts = oaiContentToParts(msg.content);+ if (parts.length === 0) parts.push(...oaiContentToParts(msg.refusal));if (Array.isArray(msg.tool_calls)) {for (const tc of msg.tool_calls) {const tcObj = tc as Record<string, unknown>;diff --git a/studio/frontend/tests/message-jsonl-import.test.ts b/studio/frontend/tests/message-jsonl-import.test.tsindex e34ba626836..a731725597e 100644--- a/studio/frontend/tests/message-jsonl-import.test.ts+++ b/studio/frontend/tests/message-jsonl-import.test.ts@@ -123,6 +123,43 @@ test("developer and assistant array content survive message JSONL import", () =>]);});+for (const layout of ["messages", "training"]) {+ test(`assistant refusals survive ${layout} JSONL import`, () => {+ const refusal = "I cannot help with that request.";+ for (const assistant of [+ { role: "assistant", content: null, refusal },+ { role: "assistant", content: "", refusal },+ { role: "assistant", content: [], refusal },+ { role: "assistant", content: [{ type: "refusal", refusal }] },+ ]) {+ const messages = [+ { role: "user", content: "A question" },+ assistant,+ { role: "user", content: "Another question" },+ ];+ const input = layout === "training"+ ? JSON.stringify({ messages })+ : messages.map((message) => JSON.stringify(message)).join("\n");+ const [conversation] = parseImportText(input, "chat.jsonl");+ assert.deepEqual(+ conversation.messages.map(({ role }) => role),+ ["user", "assistant", "user"],+ );+ assert.deepEqual(conversation.messages[1].content, [{ type: "text", text: refusal }]);+ assert.equal(conversation.messages[1].parentId, conversation.messages[0].id);+ assert.equal(conversation.messages[2].parentId, conversation.messages[1].id);+ }+ });+}++test("assistant text takes precedence over refusal metadata on import", () => {+ const [conversation] = parseImportText(+ JSON.stringify({ messages: [{ role: "assistant", content: "An explanation.", refusal: "Refused" }] }),+ "chat.jsonl",+ );+ assert.deepEqual(conversation.messages[0].content, [{ type: "text", text: "An explanation." }]);+});+test("ShareGPT import maps role aliases regardless of case and whitespace", () => {const [conversation] = parseImportText(JSON.stringify({