Skip to content

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]

Bug Fix - Address deprecation of open_text (#10208)

Ishaan Jaffb96d2ea422aa
diff --git a/litellm/utils.py b/litellm/utils.py
index 0150c4f43f2..98a9c34b470 100644
--- a/litellm/utils.py
+++ b/litellm/utils.py
@@ -180,10 +180,18 @@ from litellm.types.utils import (
all_litellm_params,
)
-with resources.open_text(
- "litellm.litellm_core_utils.tokenizers", "anthropic_tokenizer.json"
-) as f:
- json_data = json.load(f)
+try:
+ # Python 3.9+
+ with resources.files("litellm.litellm_core_utils.tokenizers").joinpath(
+ "anthropic_tokenizer.json"
+ ).open("r") as f:
+ json_data = json.load(f)
+except (ImportError, AttributeError, TypeError):
+ with resources.open_text(
+ "litellm.litellm_core_utils.tokenizers", "anthropic_tokenizer.json"
+ ) as f:
+ json_data = json.load(f)
+
# Convert to str (if necessary)
claude_json_str = json.dumps(json_data)
import importlib.metadata