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: keep generated chat titles in the conversation's language (#16413)
Debojyoti Banerjee99d1bc6686b9
diff --git a/studio/frontend/src/features/chat/utils/chat-title.ts b/studio/frontend/src/features/chat/utils/chat-title.tsindex c59556fee78..718eff8bc7f 100644--- a/studio/frontend/src/features/chat/utils/chat-title.ts+++ b/studio/frontend/src/features/chat/utils/chat-title.ts@@ -361,10 +361,10 @@ function titleMaxTokens(connection: ResolvedExternalConnection): number {}const TITLE_SYSTEM_PROMPT =- "Write 1 concise chat title summarizing the conversation topic, not the user's exact wording. Use the assistant reply as context when provided. Rules: 2-6 words, no quotes, no punctuation, ASCII only, do not echo input. Output title only.";+ "Write 1 concise chat title summarizing the conversation topic, not the user's exact wording. Use the assistant reply as context when provided. Rules: 2-6 words, no quotes, no punctuation, do not echo input. Write the title in the same language as the conversation. Output title only.";const TITLE_REFRESH_SYSTEM_PROMPT =- "Write 1 concise chat title for what this conversation is about now. The excerpt holds its latest messages, oldest first; weight the newest most. Rules: 2-6 words, no quotes, no punctuation, ASCII only, do not echo input. Output title only.";+ "Write 1 concise chat title for what this conversation is about now. The excerpt holds its latest messages, oldest first; weight the newest most. Rules: 2-6 words, no quotes, no punctuation, do not echo input. Write the title in the same language as the conversation. Output title only.";// About 250 tokens however long the chat: the last 2-3 turns, Open WebUI's {{MESSAGES:END:2}} window.const REFRESH_MESSAGE_CHARS = 300;@@ -549,7 +549,8 @@ export async function titleFromStream(export function normalizeTitle(raw: string): string | null {let title = raw.split(/\r?\n/, 1)[0] ?? "";title = title.replace(/^\s*title\s*:\s*/i, "");- title = title.replace(/[^\x20-\x7E]+/g, " ");+ // U+200C (ZWNJ) is part of Persian spelling.+ title = title.replace(/[^\x20-\x7E\p{L}\p{M}\p{N}]+/gu, " ");title = title.replace(/["'`]+/g, "");// Echo fail-safe: reject leading role labels before punctuation strips the ":".@@ -562,6 +563,6 @@ export function normalizeTitle(raw: string): string | null {const words = title.split(" ").filter(Boolean).slice(0, 6);const joined = words.join(" ").trim();- if (!joined) return null;- return joined.length > 60 ? joined.slice(0, 60).trimEnd() : joined;+ const clipped = joined.length > 60 ? cutToUnits(joined, 60).trimEnd() : joined;+ return /[^\p{M}\u200C\s]/u.test(clipped) ? clipped : null;}diff --git a/studio/frontend/tests/chat-title-clip.test.ts b/studio/frontend/tests/chat-title-clip.test.tsindex 44337f0516e..39920956edf 100644--- a/studio/frontend/tests/chat-title-clip.test.ts+++ b/studio/frontend/tests/chat-title-clip.test.ts@@ -414,7 +414,7 @@ test("a title on a saved connection is routed to it, and streamed", async () =>);assert.match(String(local?.messages?.[0]?.content),- /2-6 words, no quotes, no punctuation, ASCII only, do not echo input/,+ /2-6 words, no quotes, no punctuation, do not echo input\. Write the title in the same language as the conversation\./,);});@@ -617,7 +617,20 @@ test("the title is assembled from the deltas, unless it was cut short or reasone}});-test("the answer is reduced to a short, plain, ASCII line", () => {+test("emoji-only output still falls back instead of saving an invisible title", async () => {+ for (const raw of [+ "\u2764\uFE0F",+ "\u2615\uFE0F",+ ]) {+ assert.equal(normalizeTitle(raw), null);+ async function* chunks(): AsyncIterable<Chunk> {+ yield { choices: [{ delta: { content: raw }, finish_reason: "stop" }] } as Chunk;+ }+ assert.equal(await titleFromStream(chunks()), null);+ }+});++test("the answer is reduced to a short, plain line in its own language", () => {for (const [raw, expected] of [[' "Matrix Inversion" — Steps ', "Matrix Inversion Steps"],[@@ -632,7 +645,15 @@ test("the answer is reduced to a short, plain, ASCII line", () => {[" User: what is this", null],[`${"a".repeat(59)} b`, "a".repeat(59)],["Base: what is this", null],- ["Café — Résumé Matrix", "Caf R sum Matrix"],+ ["Café — Résumé Matrix", "Café Résumé Matrix"],+ ["Recette des crêpes à l’orange", "Recette des crêpes à l orange"],+ ["行列の逆行列の求め方", "行列の逆行列の求め方"],+ ["Привет мир", "Привет мир"],+ ["هندسه\u200Cی ماشین", "هندسه\u200Cی ماشین"],+ ["🚀 Rocket Launch ✨ Plan", "Rocket Launch Plan"],+ ["Ünïcödé — ✓ Done", "Ünïcödé Done"],+ [`${"é".repeat(59)}😀x`, "é".repeat(59)],+ ["語".repeat(80), "語".repeat(60)],["x".repeat(80), "x".repeat(60)],["Inverting Title: A Matrix", "Inverting Title A Matrix"],["Title : Matrix Steps", "Matrix Steps"],diff --git a/studio/frontend/tests/chat-title-refresh.test.ts b/studio/frontend/tests/chat-title-refresh.test.tsindex 88620492eba..aef79e26703 100644--- a/studio/frontend/tests/chat-title-refresh.test.ts+++ b/studio/frontend/tests/chat-title-refresh.test.ts@@ -101,10 +101,9 @@ test("an empty chat has nothing to title", () => {test("a refresh is as cheap as the automatic title, with its own prompt", async () => {const automatic = await buildTitleRequest(LOCAL, "User: hi");const refresh = await buildTitleRefreshRequest(LOCAL, "User: hi");- // The automatic prompt is unchanged byte for byte.assert.equal(automatic?.messages?.[0]?.content,- "Write 1 concise chat title summarizing the conversation topic, not the user's exact wording. Use the assistant reply as context when provided. Rules: 2-6 words, no quotes, no punctuation, ASCII only, do not echo input. Output title only.",+ "Write 1 concise chat title summarizing the conversation topic, not the user's exact wording. Use the assistant reply as context when provided. Rules: 2-6 words, no quotes, no punctuation, do not echo input. Write the title in the same language as the conversation. Output title only.",);assert.match(String(refresh?.messages?.[0]?.content), /latest messages/);assert.deepEqual(