From 63bdf57593cfe5db51e7eac6e58976468b9acea2 Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Tue, 9 Dec 2025 12:26:15 +0000 Subject: [PATCH] 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. --- backend/services/ollama_service.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/backend/services/ollama_service.py b/backend/services/ollama_service.py index ffdb377..e969a5e 100644 --- a/backend/services/ollama_service.py +++ b/backend/services/ollama_service.py @@ -146,19 +146,26 @@ class OllamaService: Returns: Formatted prompt string """ - prompt = f"""Analyze the following text and identify all distinct speakers or characters. -Return ONLY a JSON object with a "speakers" array containing the names of speakers. -If there are no clear speakers, return {{"speakers": ["Narrator"]}}. + prompt = f"""Analyze the following text and identify all distinct speakers or characters who need voice assignments. + +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: -- For dialogue with character names, list those characters -- For narrative text, use "Narrator" -- For mixed content, include both characters and "Narrator" if appropriate +- Text: "Alice said hello. Bob waved back." → {{"speakers": ["Narrator", "Alice", "Bob"]}} +- Text: "Once upon a time, there was a princess." → {{"speakers": ["Narrator"]}} +- Text: "The wizard spoke. 'I see danger,' he warned." → {{"speakers": ["Narrator"]}} +- Text: "Alice: Hello! Bob: Hi there!" → {{"speakers": ["Alice", "Bob"]}} Text to analyze: {text} -Return format: {{"speakers": ["Speaker1", "Speaker2", ...]}} +Return format: {{"speakers": ["Narrator", "Character1", "Character2", ...]}} """ return prompt