victor HF Staff commited on
Commit
eb6a961
·
1 Parent(s): 4a17eaf

Refine title generation prompt and logic

Browse files

Updated the preprompt for title generation to provide clearer, stricter instructions and examples for generating concise, descriptive titles. Improved fallback handling by ensuring summary is always a string and clarified that no post-processing is performed.

src/lib/server/textGeneration/title.ts CHANGED
@@ -41,14 +41,24 @@ async function generateTitle(
41
 
42
  return await getReturnFromGenerator(
43
  generateFromDefaultEndpoint({
44
- messages: [{ from: "user", content: `Prompt to summarize: "${prompt}"` }],
45
- preprompt: `You are a titling assistant.
46
- Summarize the user's request into a short title of at most 4 words.
47
- Use the SAME language as the user's message.
48
- Do not answer the question.
49
- Do not include the word prompt into your response.
50
- Do not include quotes, emojis, hashtags or trailing punctuation.
51
- Return ONLY the title text.`,
 
 
 
 
 
 
 
 
 
 
52
  generateSettings: {
53
  max_tokens: 30,
54
  },
@@ -58,7 +68,7 @@ Return ONLY the title text.`,
58
  )
59
  .then((summary) => {
60
  const firstFive = prompt.split(/\s+/g).slice(0, 5).join(" ");
61
- const trimmed = summary.trim();
62
  // Fallback: if empty, return first five words only (no emoji)
63
  return trimmed || firstFive;
64
  })
@@ -68,3 +78,5 @@ Return ONLY the title text.`,
68
  return firstFive;
69
  });
70
  }
 
 
 
41
 
42
  return await getReturnFromGenerator(
43
  generateFromDefaultEndpoint({
44
+ messages: [{ from: "user", content: `User message: "${prompt}"` }],
45
+ preprompt: `You are a chat thread titling assistant.
46
+ Goal: Produce a very short, descriptive title (2–5 words) that names the topic of the user's first message.
47
+
48
+ Rules:
49
+ - Output ONLY the title text. No prefixes, labels, quotes, emojis, hashtags, or trailing punctuation.
50
+ - Use the user's language.
51
+ - Write a noun phrase that names the topic. Do not write instructions.
52
+ - Never output just a pronoun (me/you/I/we/us/myself/yourself). Prefer a neutral subject (e.g., "Assistant", "model", or the concrete topic).
53
+ - Never include meta-words: Summarize, Summary, Title, Prompt, Topic, Subject, About, Question, Request, Chat.
54
+
55
+ Examples:
56
+ User: "Summarize hello" -> Hello
57
+ User: "How do I reverse a string in Python?" -> Python string reversal
58
+ User: "help me plan a NYC weekend" -> NYC weekend plan
59
+ User: "请解释Transformer是如何工作的" -> Transformer 工作原理
60
+ User: "tell me more about you" -> About the assistant
61
+ Return only the title text.`,
62
  generateSettings: {
63
  max_tokens: 30,
64
  },
 
68
  )
69
  .then((summary) => {
70
  const firstFive = prompt.split(/\s+/g).slice(0, 5).join(" ");
71
+ const trimmed = String(summary ?? "").trim();
72
  // Fallback: if empty, return first five words only (no emoji)
73
  return trimmed || firstFive;
74
  })
 
78
  return firstFive;
79
  });
80
  }
81
+
82
+ // No post-processing: rely solely on prompt instructions above