From a5808f9de0fb8a1eb4b4e30464aa435af7325423 Mon Sep 17 00:00:00 2001 From: vegu-ai-tools <152010387+vegu-ai-tools@users.noreply.github.com> Date: Fri, 1 May 2026 13:22:15 +0300 Subject: [PATCH] fix: prevent duplicated character descriptions in prompts --- CHANGELOG.yaml | 1 + src/talemate/character.py | 3 ++- src/talemate/prompts/templates/common/character-context.jinja2 | 2 +- src/talemate/prompts/templates/conversation/dialogue.jinja2 | 2 +- .../creator/contextual-generate/context-rendering.jinja2 | 2 +- .../creator/determine-character-dialogue-examples.jinja2 | 2 +- .../creator/determine-character-dialogue-instructions.jinja2 | 2 +- .../prompts/templates/creator/determine-character-goals.jinja2 | 2 +- src/talemate/prompts/templates/director/cm-assign-voice.jinja2 | 2 +- src/talemate/prompts/templates/narrator/narrate-context.jinja2 | 2 +- 10 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.yaml b/CHANGELOG.yaml index 9be4a22c..c59a2115 100644 --- a/CHANGELOG.yaml +++ b/CHANGELOG.yaml @@ -48,6 +48,7 @@ - "macOS Modifiers: Ctrl+click affordances throughout the UI now also accept Cmd (Meta) on macOS, where the OS reserves Ctrl+click for the system context menu. Tooltips, hints, and docs label the modifier as Cmd on Mac and Ctrl elsewhere. Affects regenerate, scene tools (narrator/director/actor/creative), world state manager, contextual generate, message asset image, autocomplete (Ctrl+Enter), and history navigation. (#261)" - "Game Loop Actor Iter: Fixed a bug where the `game_loop_actor_iter` event was only firing for player turns, so agents that listen for actor iteration (like passive narration) silently skipped AI turns." - "OpenRouter: Fixed redundant provider/model list fetches when multiple OpenRouter clients are configured. Concurrent `status()` calls all saw the fetched-flag as still false and each kicked off its own HTTP request; the fetches are now serialized with an asyncio lock and double-checked locking so only one request runs." + - "Character Prompts: Fixed duplicated character description in prompts. When the LLM-generated character sheet contained a `description` attribute (common — the extractor often emits one), it was rendered alongside the standalone description field, repeating the same text twice. Templates that render both now filter `description` out of the sheet (case-insensitive). Affects the dialogue, narrator, director (voice assignment), and creator (dialogue examples, dialogue instructions, character goals, contextual generate) prompt paths." improvements: - "System Prompt Override Indicators: The system prompt override list now shows a pencil icon next to entries that have an active override, making it easy to see which prompts have been customized." - "Search Strictness: The distance_mod embedding preset value is now a float (was int) with a range of 0.1–2.0, allowing both tighter and looser similarity matching. A 'Search Strictness' slider is now available in the Context Database UI, letting users tune search sensitivity on the fly. Changes persist to the active embedding preset immediately." diff --git a/src/talemate/character.py b/src/talemate/character.py index 33829449..51ea72bc 100644 --- a/src/talemate/character.py +++ b/src/talemate/character.py @@ -140,10 +140,11 @@ class Character(pydantic.BaseModel): "description": self.description, } + exclude_lower = {e.lower() for e in exclude} sheet_list = [] for key, value in sheet.items(): - if key not in exclude: + if key.lower() not in exclude_lower: sheet_list.append(f"{key}: {value}") return "\n".join(sheet_list) diff --git a/src/talemate/prompts/templates/common/character-context.jinja2 b/src/talemate/prompts/templates/common/character-context.jinja2 index 4850e971..4b60648c 100644 --- a/src/talemate/prompts/templates/common/character-context.jinja2 +++ b/src/talemate/prompts/templates/common/character-context.jinja2 @@ -2,7 +2,7 @@ {# active characters #}{% for character in characters|default(scene.characters) %} {% if not skip_characters or character.name not in skip_characters %} ### {{ character.name }} -{% if not skip_sheet %}{{ character.sheet }}{% endif %} +{% if not skip_sheet %}{{ character.sheet_filtered("description") }}{% endif %} {% if query_personality -%} {{ query_memory("what is "+character.name+"'s personality?", as_question_answer=False) }} diff --git a/src/talemate/prompts/templates/conversation/dialogue.jinja2 b/src/talemate/prompts/templates/conversation/dialogue.jinja2 index 73cb4c2e..1a720ace 100644 --- a/src/talemate/prompts/templates/conversation/dialogue.jinja2 +++ b/src/talemate/prompts/templates/conversation/dialogue.jinja2 @@ -11,7 +11,7 @@ Override example: <|SECTION:CHARACTERS|> {% for character in characters %} ### {{ character.name }} -{{ character.sheet }} +{{ character.sheet_filtered("description") }} {{ character.description }} {% endfor %} diff --git a/src/talemate/prompts/templates/creator/contextual-generate/context-rendering.jinja2 b/src/talemate/prompts/templates/creator/contextual-generate/context-rendering.jinja2 index 3d6321ef..766940de 100644 --- a/src/talemate/prompts/templates/creator/contextual-generate/context-rendering.jinja2 +++ b/src/talemate/prompts/templates/creator/contextual-generate/context-rendering.jinja2 @@ -103,7 +103,7 @@ {{ character.description }} {% if not character or not character.name %}name: {{ character_name }}{% endif %} -{{ character.sheet_filtered(context_name) }} +{{ character.sheet_filtered(context_name, "description") }} {% else %} {{ character.sheet }} {% endif %} diff --git a/src/talemate/prompts/templates/creator/determine-character-dialogue-examples.jinja2 b/src/talemate/prompts/templates/creator/determine-character-dialogue-examples.jinja2 index 5679aafd..782efb6f 100644 --- a/src/talemate/prompts/templates/creator/determine-character-dialogue-examples.jinja2 +++ b/src/talemate/prompts/templates/creator/determine-character-dialogue-examples.jinja2 @@ -6,7 +6,7 @@ {# CHARACTER CONTEXT #} {% set character_context %} <|SECTION:CHARACTER|> -{{ character.sheet }} +{{ character.sheet_filtered("description") }} {{ character.description }} <|CLOSE_SECTION|> {% endset %} diff --git a/src/talemate/prompts/templates/creator/determine-character-dialogue-instructions.jinja2 b/src/talemate/prompts/templates/creator/determine-character-dialogue-instructions.jinja2 index e9a60dac..16221dc8 100644 --- a/src/talemate/prompts/templates/creator/determine-character-dialogue-instructions.jinja2 +++ b/src/talemate/prompts/templates/creator/determine-character-dialogue-instructions.jinja2 @@ -8,7 +8,7 @@ Override example: -#} {% set extra_context_content %} <|SECTION:CHARACTER|> -{{ character.sheet }} +{{ character.sheet_filtered("description") }} {{ character.description }} <|CLOSE_SECTION|> {% include "task-information.jinja2" %} diff --git a/src/talemate/prompts/templates/creator/determine-character-goals.jinja2 b/src/talemate/prompts/templates/creator/determine-character-goals.jinja2 index 96f26350..872b4dd3 100644 --- a/src/talemate/prompts/templates/creator/determine-character-goals.jinja2 +++ b/src/talemate/prompts/templates/creator/determine-character-goals.jinja2 @@ -14,7 +14,7 @@ Override example: <|SECTION:CHARACTERS|> {% for character in scene.characters %} ### {{ character.name }} -{{ character.sheet }} +{{ character.sheet_filtered("description") }} {{ character.description }} {% endfor %} diff --git a/src/talemate/prompts/templates/director/cm-assign-voice.jinja2 b/src/talemate/prompts/templates/director/cm-assign-voice.jinja2 index 87758ed7..a8eb414d 100644 --- a/src/talemate/prompts/templates/director/cm-assign-voice.jinja2 +++ b/src/talemate/prompts/templates/director/cm-assign-voice.jinja2 @@ -5,7 +5,7 @@ <|SECTION:CHARACTER DETAILS - {{ character.name }}|> {{ character.description }} -{{ character.sheet }} +{{ character.sheet_filtered("description") }} <|CLOSE_SECTION|> <|SECTION:VOICES|> {% for voice in voices %} diff --git a/src/talemate/prompts/templates/narrator/narrate-context.jinja2 b/src/talemate/prompts/templates/narrator/narrate-context.jinja2 index be511bb6..e70710ab 100644 --- a/src/talemate/prompts/templates/narrator/narrate-context.jinja2 +++ b/src/talemate/prompts/templates/narrator/narrate-context.jinja2 @@ -13,7 +13,7 @@ {% endif %} {% if feature_character is defined %} <|SECTION:{{ feature_character.name|upper }}|> -{{ feature_character.sheet }} +{{ feature_character.sheet_filtered("description") }} {{ feature_character.description }} <|CLOSE_SECTION|>