From abc381cfe2ad73ecca617b7dfd2d3f7b6c774f16 Mon Sep 17 00:00:00 2001 From: Chesars Date: Wed, 4 Mar 2026 21:53:03 -0300 Subject: [PATCH] fix: use chat format in tools test, include tools/system in local fallback --- litellm/main.py | 6 +++++- tests/test_litellm/test_count_tokens_public_api.py | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/litellm/main.py b/litellm/main.py index e70055a90a..8be923685a 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -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( diff --git a/tests/test_litellm/test_count_tokens_public_api.py b/tests/test_litellm/test_count_tokens_public_api.py index 59a1092455..81ba244796 100644 --- a/tests/test_litellm/test_count_tokens_public_api.py +++ b/tests/test_litellm/test_count_tokens_public_api.py @@ -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"}}}, + }, } ]