fix: use chat format in tools test, include tools/system in local fallback

This commit is contained in:
Chesars
2026-03-04 21:53:03 -03:00
parent 8786e674ee
commit abc381cfe2
2 changed files with 10 additions and 4 deletions
+5 -1
View File
@@ -7617,9 +7617,13 @@ async def acount_tokens(
)
# Fallback to local tiktoken-based token counting
fallback_messages = messages or []
if system and fallback_messages:
fallback_messages = [{"role": "system", "content": system}] + fallback_messages
local_count = litellm.token_counter(
model=model,
messages=messages or [],
messages=fallback_messages,
tools=tools,
)
return TokenCountResponse(
@@ -71,9 +71,11 @@ def test_acount_tokens_with_tools():
tools = [
{
"type": "function",
"name": "get_weather",
"description": "Get weather info",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}},
"function": {
"name": "get_weather",
"description": "Get weather info",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}},
},
}
]