From 5d428ac94c2f9226dab1bba382db7acaeda0824c Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Thu, 28 Mar 2024 13:48:34 -0700 Subject: [PATCH] fix(utils.py): don't add chatml tokens to a simple text token count --- litellm/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/litellm/utils.py b/litellm/utils.py index 88b95203135..fa15b73c229 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -3597,6 +3597,8 @@ def token_counter( raise ValueError("text and messages cannot both be None") elif isinstance(text, List): text = "".join(t for t in text if isinstance(t, str)) + elif isinstance(text, str): + count_response_tokens = True # user just trying to count tokens for a text. don't add the chat_ml +3 tokens to this if model is not None: tokenizer_json = _select_tokenizer(model=model)