From d24e2fbfc9a0413a278ea585faa7a1b1d3157dca Mon Sep 17 00:00:00 2001 From: vegu-ai-tools <152010387+vegu-ai-tools@users.noreply.github.com> Date: Sun, 3 May 2026 21:10:44 +0300 Subject: [PATCH] fix: handle empty question case in reinforcement context --- .../templates/world_state/update-reinforcements.jinja2 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/talemate/prompts/templates/world_state/update-reinforcements.jinja2 b/src/talemate/prompts/templates/world_state/update-reinforcements.jinja2 index 84e93318..5de79170 100644 --- a/src/talemate/prompts/templates/world_state/update-reinforcements.jinja2 +++ b/src/talemate/prompts/templates/world_state/update-reinforcements.jinja2 @@ -28,8 +28,12 @@ Override example: {% set rendered_context_tokens = count_tokens(rendered_context) %} {% set volatile_context_tokens = count_tokens(volatile_context_text) %} {% set scene_history = scene.context_history(budget=max_tokens-200-rendered_context_tokens-volatile_context_tokens, keep_context_investigation=False) -%} +{% if scene_history %} {% set last_message = scene_history[-1] %} {% set last_message_is_reinforcement = ("internal notes" in last_message.lower() and question in last_message) %} +{% else %} +{% set last_message_is_reinforcement = false %} +{% endif %} {% if not last_message_is_reinforcement %}{% set final_line_number=len(scene_history) %}{% else %}{% set final_line_number=len(scene_history)-1 %}{% endif %} {# END PREPARE SCENE HISTORY #} @@ -66,7 +70,7 @@ No dialogue so far <|SECTION:TASK|> {# QUESTION #} -{%- if question.strip()[-1] == '?' %} +{%- if question.strip() and question.strip()[-1] == '?' %} Shortly answer the following question: {{ question }} Consider the entire context and honor the sequentiality of the dialogue. Answer based on the final state of the dialogue.