mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-07-27 21:05:34 +00:00
Closes #607. Assistant tool-call turns can carry content=None, which crashed token estimation (len(m.content)) and think-tag stripping. Normalize with 'content or ""', route native OpenHands truncation through the shared estimate_prompt_tokens, and add tests for the estimator, the truncation helper, and an end-to-end tool-call run with None content.
18 lines
546 B
Python
18 lines
546 B
Python
from __future__ import annotations
|
|
|
|
from openjarvis.core.types import Message, Role, ToolCall
|
|
from openjarvis.engine._base import estimate_prompt_tokens
|
|
|
|
|
|
def test_estimate_prompt_tokens_handles_none_content_tool_call_turn() -> None:
|
|
messages = [
|
|
Message(role=Role.USER, content="hi"),
|
|
Message(
|
|
role=Role.ASSISTANT,
|
|
content=None, # type: ignore[arg-type]
|
|
tool_calls=[ToolCall(id="call_1", name="lookup", arguments="{}")],
|
|
),
|
|
]
|
|
|
|
assert estimate_prompt_tokens(messages) == 8
|