The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(utils.py): fix select tokenizer for custom tokenizer (#7599)
Krish Dholakia07c5f136f158
diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yamlindex 91dca93acf5..280109dbc18 100644--- a/litellm/proxy/_new_secret_config.yaml+++ b/litellm/proxy/_new_secret_config.yaml@@ -10,13 +10,21 @@ model_list:api_key: os.environ/OPENAI_API_KEY- model_name: chatbot_actionslitellm_params:- model: langfuse/openai-gpt-3.5-turbo+ model: langfuse/azure/gpt-4o+ api_base: "os.environ/AZURE_API_BASE"+ api_key: "os.environ/AZURE_API_KEY"tpm: 1000000prompt_id: "jokes"- - model_name: openai-gpt-3.5-turbo+ - model_name: openai-deepseeklitellm_params:- model: openai/gpt-3.5-turbo+ model: deepseek/deepseek-chatapi_key: os.environ/OPENAI_API_KEY+ model_info:+ access_groups: ["restricted-models"]+ custom_tokenizer:+ identifier: deepseek-ai/DeepSeek-V3-Base+ revision: main+ auth_token: os.environ/HUGGINGFACE_API_KEYlitellm_settings:diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 5890787bf17..54b3314f833 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -5606,6 +5606,7 @@ async def token_counter(request: TokenCountRequest):_tokenizer_used = litellm.utils._select_tokenizer(model=model_to_use, custom_tokenizer=custom_tokenizer)+tokenizer_used = str(_tokenizer_used["type"])total_tokens = token_counter(model=model_to_use,diff --git a/litellm/router.py b/litellm/router.pyindex 1da1a977304..bfa7708854e 100644--- a/litellm/router.py+++ b/litellm/router.py@@ -4379,7 +4379,7 @@ class Router:pass## GET LITELLM MODEL INFO - raises exception, if model is not mapped- if not model.startswith(custom_llm_provider):+ if not model.startswith("{}/".format(custom_llm_provider)):model_info_name = "{}/{}".format(custom_llm_provider, model)else:model_info_name = modeldiff --git a/litellm/utils.py b/litellm/utils.pyindex 00b57cef17e..6051a873272 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -1278,12 +1278,12 @@ def _select_tokenizer(model: str, custom_tokenizer: Optional[CustomHuggingfaceTokenizer] = None):if custom_tokenizer is not None:- custom_tokenizer = Tokenizer.from_pretrained(- custom_tokenizer["identifier"],+ _tokenizer = create_pretrained_tokenizer(+ identifier=custom_tokenizer["identifier"],revision=custom_tokenizer["revision"],auth_token=custom_tokenizer["auth_token"],)- return {"type": "huggingface_tokenizer", "tokenizer": custom_tokenizer}+ return _tokenizerreturn _select_tokenizer_helper(model=model)