fix: Improve Ollama prompt to always detect Narrator role
Updated the speaker detection prompt to explicitly instruct the AI to: - Identify narrative text and assign it to 'Narrator' - Detect character dialogue and list character names - Include BOTH Narrator and characters when story has mixed content This ensures stories with narrative descriptions get proper voice assignments for both the narrator and speaking characters. Example: Story with 'Once upon a time...' narrative and dialogue from Lily, Benny, Sammy now correctly detects all 4 roles.
This commit is contained in:
@@ -146,19 +146,26 @@ class OllamaService:
|
|||||||
Returns:
|
Returns:
|
||||||
Formatted prompt string
|
Formatted prompt string
|
||||||
"""
|
"""
|
||||||
prompt = f"""Analyze the following text and identify all distinct speakers or characters.
|
prompt = f"""Analyze the following text and identify all distinct speakers or characters who need voice assignments.
|
||||||
Return ONLY a JSON object with a "speakers" array containing the names of speakers.
|
|
||||||
If there are no clear speakers, return {{"speakers": ["Narrator"]}}.
|
CRITICAL: Look for TWO types of content:
|
||||||
|
1. NARRATIVE TEXT: Descriptions, scene-setting, "he said", "she thought", etc. → This needs "Narrator"
|
||||||
|
2. CHARACTER DIALOGUE: Direct speech by characters → These need character names
|
||||||
|
|
||||||
|
You MUST include "Narrator" if there is ANY narrative text, descriptions, or non-dialogue content.
|
||||||
|
|
||||||
|
Return ONLY a JSON object with a "speakers" array.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
- For dialogue with character names, list those characters
|
- Text: "Alice said hello. Bob waved back." → {{"speakers": ["Narrator", "Alice", "Bob"]}}
|
||||||
- For narrative text, use "Narrator"
|
- Text: "Once upon a time, there was a princess." → {{"speakers": ["Narrator"]}}
|
||||||
- For mixed content, include both characters and "Narrator" if appropriate
|
- Text: "The wizard spoke. 'I see danger,' he warned." → {{"speakers": ["Narrator"]}}
|
||||||
|
- Text: "Alice: Hello! Bob: Hi there!" → {{"speakers": ["Alice", "Bob"]}}
|
||||||
|
|
||||||
Text to analyze:
|
Text to analyze:
|
||||||
{text}
|
{text}
|
||||||
|
|
||||||
Return format: {{"speakers": ["Speaker1", "Speaker2", ...]}}
|
Return format: {{"speakers": ["Narrator", "Character1", "Character2", ...]}}
|
||||||
"""
|
"""
|
||||||
return prompt
|
return prompt
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user