mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-15 14:22:43 +00:00
test(model_metadata): cache tools schema token estimate
Adds a regression test that repeated request-token estimates do not re-serialize the same tool schema list.
This commit is contained in:
parent
32a0f9e17a
commit
f4d5cfd0fd
1 changed files with 23 additions and 0 deletions
|
|
@ -30,6 +30,7 @@ from agent.model_metadata import (
|
|||
save_context_length,
|
||||
fetch_model_metadata,
|
||||
_MODEL_CACHE_TTL,
|
||||
estimate_request_tokens_rough,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -120,6 +121,28 @@ class TestEstimateMessagesTokensRough:
|
|||
assert result < 5000
|
||||
|
||||
|
||||
class TestEstimateRequestTokensRough:
|
||||
def test_caches_tools_estimate(self):
|
||||
messages = [{"role": "user", "content": "hello"}]
|
||||
tools = [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "terminal",
|
||||
"description": "Run a command",
|
||||
"parameters": {"type": "object", "properties": {"command": {"type": "string"}}},
|
||||
},
|
||||
}
|
||||
]
|
||||
|
||||
# json.dumps is used for params sizing; ensure the tools estimate is cached
|
||||
# so repeated calls don't keep re-serializing the same schema list.
|
||||
with patch("agent.model_metadata.json.dumps", wraps=__import__("json").dumps) as dumps:
|
||||
estimate_request_tokens_rough(messages, system_prompt="x" * 8, tools=tools)
|
||||
estimate_request_tokens_rough(messages, system_prompt="x" * 8, tools=tools)
|
||||
assert dumps.call_count == 1
|
||||
|
||||
|
||||
# =========================================================================
|
||||
# Default context lengths
|
||||
# =========================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue