Skip to content

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.

Studio: import ShareGPT chats with the right roles (#11149)

Nilay9138eb9c0d9e
diff --git a/studio/frontend/src/features/chat/utils/chat-import.ts b/studio/frontend/src/features/chat/utils/chat-import.ts
index dd4b23f86b2..57f86b8f731 100644
--- a/studio/frontend/src/features/chat/utils/chat-import.ts
+++ b/studio/frontend/src/features/chat/utils/chat-import.ts
@@ -206,6 +206,14 @@ function oaiMessagesToRecords(
return records;
}
+const SHAREGPT_ROLES = new Map<string, MessageRecord["role"]>([
+ ["human", "user"],
+ ["user", "user"],
+ ["gpt", "assistant"],
+ ["assistant", "assistant"],
+ ["system", "system"],
+]);
+
function sharegptToRecords(
conversations: unknown[],
threadId: string,
@@ -219,7 +227,7 @@ function sharegptToRecords(
const from = typeof conv.from === "string" ? conv.from : "";
const value = typeof conv.value === "string" ? conv.value : "";
if (!value.trim()) continue;
- const role: MessageRecord["role"] = from === "human" ? "user" : from === "system" ? "system" : "assistant";
+ const role = SHAREGPT_ROLES.get(from.trim().toLowerCase()) ?? "assistant";
const id = crypto.randomUUID();
records.push({
id,
diff --git a/studio/frontend/tests/message-jsonl-import.test.ts b/studio/frontend/tests/message-jsonl-import.test.ts
index 58c2e4d73ad..f1d9e4c3164 100644
--- a/studio/frontend/tests/message-jsonl-import.test.ts
+++ b/studio/frontend/tests/message-jsonl-import.test.ts
@@ -92,6 +92,28 @@ test("developer and assistant array content survive message JSONL import", () =>
]);
});
+test("ShareGPT import maps role aliases regardless of case and whitespace", () => {
+ const [conversation] = parseImportText(
+ JSON.stringify({
+ conversations: [
+ { from: "system", value: "Be brief" },
+ { from: "user", value: "Hi" },
+ { from: "assistant", value: "Hello" },
+ { from: "Human", value: "Again" },
+ { from: " GPT ", value: "Sure" },
+ { from: "HUMAN", value: "Bye" },
+ { from: "constructor", value: "Unknown" },
+ ],
+ }),
+ "sharegpt.jsonl",
+ );
+
+ assert.deepEqual(
+ conversation.messages.map(({ role }) => role),
+ ["system", "user", "assistant", "user", "assistant", "user", "assistant"],
+ );
+});
+
test("assistant images are represented explicitly in JSONL exports", () => {
const exported = structuredClone(
messageToOpenAI({