From 78c13ccf015f2a2324259c46f82bb8a74cff98c2 Mon Sep 17 00:00:00 2001 From: Kagamine Rin Date: Sun, 31 May 2026 10:51:50 -0400 Subject: [PATCH] fix: move punctuation logic to LLM - backend returns complete joined text The frontend no longer does separator/punctuation logic. Both Maestro modes (generate and complete) now simply setPrompt(result). The LLM is instructed to return the user's exact words + continuation, properly joined. This is the right layer for text joining decisions. --- backend/src/text_gen.py | 11 +++----- frontend/src/components/Generator.tsx | 36 +++------------------------ 2 files changed, 7 insertions(+), 40 deletions(-) diff --git a/backend/src/text_gen.py b/backend/src/text_gen.py index 078b060..cc6fdc6 100644 --- a/backend/src/text_gen.py +++ b/backend/src/text_gen.py @@ -127,18 +127,15 @@ Output ONLY the prompt text. No numbers, no labels, no commentary.""" MAESTRO_COMPLETE_PROMPT = """You are Maestro, an expert music prompt writer for AI music generation models (specifically Google Lyria). -The user has written the beginning of a prompt and wants you to continue it. Here is what they have: +The user has started writing a prompt and wants you to continue it. Here is what they have: "{user_input}" -Continue and expand their idea. Add 2-3 sentences of specific musical detail — genre, instrumentation, mood, tempo, structure, production style. Your continuation will be appended directly after their text, so: +Continue their idea by adding 2-3 sentences of specific musical detail — genre, instrumentation, mood, tempo, structure, production style. -- Do NOT repeat or rephrase what they wrote -- Do NOT add a period if their text ends mid-sentence -- Start naturally as if picking up from where they left off -- Be vivid and specific — a producer should be able to generate from this +Return the COMPLETE prompt: the user's EXACT words, followed by your continuation, properly joined. Do not rephrase, rewrite, or change any of the user's words. Just continue from where they left off. -Output ONLY your continuation text. No labels, no commentary, no quotes.""" +Output ONLY the complete prompt text. No labels, no commentary, no quotes.""" MAESTRO_STRUCTURED_PROMPT = """You are Maestro, an expert music prompt writer for AI music generation models (specifically Google Lyria). diff --git a/frontend/src/components/Generator.tsx b/frontend/src/components/Generator.tsx index 7d5c97a..9607d56 100644 --- a/frontend/src/components/Generator.tsx +++ b/frontend/src/components/Generator.tsx @@ -187,23 +187,8 @@ export default function Generator({ onGenerate }: Props) { { - if (mode === 'complete') { - // Append continuation to existing prompt - setPrompt(prev => { - const trimmed = prev.trimEnd() - const endsWithPunct = /[.!?,;:]$/.test(trimmed) - const startsLower = /^[a-z]/.test(result) - // Already punctuated? Just space. - // Flows naturally (lowercase)? Just space. - // Otherwise: period + space for a new sentence. - const separator = (endsWithPunct || startsLower) ? ' ' : '. ' - return trimmed + separator + result - }) - } else { - // Generate mode: replace empty prompt - setPrompt(result) - } + onResult={(_result, _mode) => { + setPrompt(_result) setError('') }} onError={(msg) => setError(msg)} @@ -226,22 +211,7 @@ export default function Generator({ onGenerate }: Props) { { - if (mode === 'complete') { - // Fallback: append to additional field - setStructuredPrompt(prev => { - const existing = prev.additional?.trim() || '' - const endsWithPunct = /[.!?,;:]$/.test(existing) - const startsLower = /^[a-z]/.test(result) - const separator = (endsWithPunct || startsLower) ? ' ' : '. ' - return { ...prev, additional: existing + separator + result } - }) - } else { - // Generate: put in additional - setStructuredPrompt(prev => ({ ...prev, additional: result })) - } - setError('') - }} + onResult={(_result, _mode) => { /* handled by onStructuredResult */ }} onStructuredResult={(fields, mode) => { // Structured mode: merge fields into structuredPrompt, preserving user edits setStructuredPrompt(prev => ({