Fixed llm context for turns

This commit is contained in:
Dejvino
2026-07-01 22:24:46 +02:00
parent 0140e2e8d9
commit 6403d46052
6 changed files with 14 additions and 31 deletions
+4 -4
View File
@@ -5,12 +5,12 @@ from .prompts import SYSTEM_PROMPT
from . import state
def build_system_prompt() -> str:
def build_system_prompt(recent_narrative: str | None = None, recent_log: str | None = None) -> str:
"""Assemble the system prompt with current game state."""
char = state.read_file(CHAR_PATH) or "*No character sheet.*"
world = state.truncate_world(state.read_file(WORLD_PATH) or "") or "*No world state.*"
log = state.read_recent_log()
story = state.read_recent_book()
log = recent_log if recent_log is not None else state.read_recent_log()
story = recent_narrative if recent_narrative is not None else state.read_recent_book(2)
return SYSTEM_PROMPT.substitute(
character=char, world=world, log=log, story=story
character=char, world=world, log=log, story=story,
)
+5 -1
View File
@@ -40,8 +40,12 @@ def read_recent_book(max_turns: int = 1) -> str:
if not text:
return "*No prior story.*"
turns = text.split("\n## ")
if len(turns) <= 1:
return turns[0]
recent = turns[-max_turns:]
return "\n## ".join(recent) if len(turns) > 1 else recent[0]
if not recent[0].startswith("## "):
recent[0] = "## " + recent[0]
return "\n## ".join(recent)
def truncate_world(text: str) -> str:
+1 -3
View File
@@ -101,6 +101,4 @@ def validate_action(
return False, "Unrecognized"
def auto_prompt(book_log: str = "") -> str:
"""Fallback player prompt."""
return "**What do you do?**"