fix: improve TTS filename generation with strict prompt and fallback
- Enhanced system prompt: MUST generate title, NEVER refuse - Clear instructions for edge cases (empty, inappropriate, nonsensical text) - Added fallback logic if Hermes returns empty or refusal messages - Fallback uses first 30 chars of text or 'audio-file' as last resort - Ensures downloads always have a valid filename
This commit is contained in:
parent
46f74eab59
commit
0213a7e632
1 changed files with 11 additions and 3 deletions
14
src/tts.js
14
src/tts.js
|
|
@ -203,7 +203,7 @@ export async function generateTitleForTTS(text) {
|
|||
messages: [
|
||||
{
|
||||
role: "system",
|
||||
content: "Generate a concise 5-10 word filename title for the following text. Return only the title words, no quotes, no explanation. Focus on the main topic or key concept. Example: 'Machine Learning Basics Tutorial' or 'Recipe For Chocolate Chip Cookies' or 'JavaScript Array Methods Guide'.",
|
||||
content: "You MUST generate a filename for the text provided. NEVER refuse. Return ONLY a 5-10 word title, nothing else. No quotes, no explanation, no refusal. If the text is inappropriate, nonsensical, or empty, create a descriptive title anyway (e.g., 'Random Text Sample', 'Test Audio File', 'User Generated Content'). Examples: 'Machine Learning Tutorial Notes', 'Daily Journal Entry', 'Shopping List Items'. YOU MUST ALWAYS RETURN A TITLE.",
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
|
|
@ -221,8 +221,16 @@ export async function generateTitleForTTS(text) {
|
|||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.choices[0].message.content
|
||||
.trim()
|
||||
let title = data.choices[0].message.content.trim();
|
||||
|
||||
// Fallback if Hermes returns empty or refuses
|
||||
if (!title || title.length < 3 || title.toLowerCase().includes("cannot") || title.toLowerCase().includes("inappropriate")) {
|
||||
// Generate a fallback title based on text preview
|
||||
const preview = text.substring(0, 30).replace(/[^\w\s]/g, "").trim();
|
||||
title = preview || "audio-file";
|
||||
}
|
||||
|
||||
return title
|
||||
.replace(/['"]/g, "") // Remove quotes
|
||||
.replace(/[^\w\s-]/g, "") // Remove special characters except spaces and hyphens
|
||||
.replace(/\s+/g, "-") // Replace spaces with hyphens
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue