fix(tests): update recent history truncation to use token limits
This commit is contained in:
@@ -222,18 +222,23 @@ def test_recent_history_capped_at_max(tmp_path) -> None:
|
|||||||
assert f"entry-{builder._MAX_RECENT_HISTORY + 19}" in prompt
|
assert f"entry-{builder._MAX_RECENT_HISTORY + 19}" in prompt
|
||||||
|
|
||||||
|
|
||||||
def test_recent_history_truncated_at_max_chars(tmp_path) -> None:
|
def test_recent_history_truncated_at_max_tokens(tmp_path) -> None:
|
||||||
"""Recent History section must be truncated at _MAX_HISTORY_CHARS."""
|
"""Recent History section must be truncated to _MAX_HISTORY_TOKENS."""
|
||||||
|
import tiktoken
|
||||||
|
|
||||||
workspace = _make_workspace(tmp_path)
|
workspace = _make_workspace(tmp_path)
|
||||||
builder = ContextBuilder(workspace)
|
builder = ContextBuilder(workspace)
|
||||||
|
|
||||||
big_entry = "x" * (builder._MAX_HISTORY_CHARS + 5_000)
|
big_entry = "word " * (builder._MAX_HISTORY_TOKENS + 5_000)
|
||||||
builder.memory.append_history(big_entry)
|
builder.memory.append_history(big_entry)
|
||||||
|
|
||||||
prompt = builder.build_system_prompt()
|
prompt = builder.build_system_prompt()
|
||||||
history_section = prompt.split("# Recent History\n\n", 1)
|
history_section = prompt.split("# Recent History\n\n", 1)
|
||||||
assert len(history_section) == 2
|
assert len(history_section) == 2
|
||||||
assert len(history_section[1]) < builder._MAX_HISTORY_CHARS + 200
|
|
||||||
|
enc = tiktoken.get_encoding("cl100k_base")
|
||||||
|
# Small margin for the truncation suffix appended after the token slice.
|
||||||
|
assert len(enc.encode(history_section[1])) <= builder._MAX_HISTORY_TOKENS + 50
|
||||||
|
|
||||||
|
|
||||||
def test_no_recent_history_when_dream_has_processed_all(tmp_path) -> None:
|
def test_no_recent_history_when_dream_has_processed_all(tmp_path) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user