fix: soften Lyria API error messages
Error messages no longer over-attribute failures to user prompt phrasing. The Lyria API has strict/loose constraints we haven't fully mapped yet, so blaming the user's prompt when the API silently returns no audio is misleading. Updated messages to acknowledge the API as the source.
This commit is contained in:
1 parent
43d3db6bed
commit
fb3c3c7c05
1 file changed
+5
-5
@@ -51,24 +51,24 @@ async def generate_clip(prompt: str, model: str = "lyria-3-clip-preview", durati
|
||||
if block_reason:
|
||||
block_message = data.get("blockReasonMessage", "")
|
||||
logger.warning(f"Google Lyria API blocked: {block_reason} — {block_message}")
|
||||
return {"success": False, "error": f"Prompt was filtered. Try describing the sound using mood, instruments, and tempo instead of genre names. ({block_message or block_reason})"}
|
||||
return {"success": False, "error": f"Prompt was filtered by the Lyria API. ({block_message or block_reason}) Try rephrasing your description."}
|
||||
|
||||
# Extract base64 audio from response
|
||||
# Google Lyria returns parts array: first part may be text (e.g. "<instrumental>"),
|
||||
# audio is in inlineData of a subsequent part.
|
||||
candidates = data.get("candidates", [])
|
||||
if not candidates:
|
||||
return {"success": False, "error": "Prompt was filtered. Try describing the sound using mood, instruments, and tempo instead of genre names."}
|
||||
return {"success": False, "error": "Prompt was filtered by the Lyria API. Try rephrasing your description."}
|
||||
|
||||
# Check finish_reason for blocks
|
||||
finish_reason = candidates[0].get("finishReason", "")
|
||||
if finish_reason == "SAFETY":
|
||||
return {"success": False, "error": "Prompt was filtered by safety controls. Try rephrasing — describe the sound using mood, instruments, and tempo instead of specific genre or artist names."}
|
||||
return {"success": False, "error": "Prompt was filtered by safety controls. Try rephrasing your description — avoid specific artist or brand names."}
|
||||
|
||||
content = candidates[0].get("content", {})
|
||||
parts = content.get("parts", [])
|
||||
if not parts:
|
||||
return {"success": False, "error": "No audio was generated. Try rephrasing your prompt — describe the sound using mood, instruments, and tempo."}
|
||||
return {"success": False, "error": "The Lyria API returned no content. This can happen with certain prompts — try rephrasing or adjusting your description."}
|
||||
|
||||
# Find the part with inlineData (audio) — not necessarily parts[0]
|
||||
audio_part = None
|
||||
@@ -79,7 +79,7 @@ async def generate_clip(prompt: str, model: str = "lyria-3-clip-preview", durati
|
||||
|
||||
if audio_part is None:
|
||||
# No audio in any part — likely filtered
|
||||
return {"success": False, "error": "No audio was generated. Try rephrasing your prompt — describe the sound using mood, instruments, and tempo instead of specific genre names."}
|
||||
return {"success": False, "error": "The Lyria API accepted the prompt but returned no audio. Try rephrasing your description."}
|
||||
|
||||
inline_data = audio_part.get("inlineData", {})
|
||||
mime_type = inline_data.get("mimeType", "")
|
||||
|
||||
Reference in new issue
Block a user