Skip to content

Commit b96d2ea

Browse files
ishaan-jaffnjbrake
andauthored
Bug Fix - Address deprecation of open_text (#10208)
* Update utils.py (#10201) * fixes importlib --------- Co-authored-by: Nathan Brake <[email protected]>
1 parent 868cdd0 commit b96d2ea

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

litellm/utils.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,18 @@
180180
all_litellm_params,
181181
)
182182

183-
with resources.open_text(
184-
"litellm.litellm_core_utils.tokenizers", "anthropic_tokenizer.json"
185-
) as f:
186-
json_data = json.load(f)
183+
try:
184+
# Python 3.9+
185+
with resources.files("litellm.litellm_core_utils.tokenizers").joinpath(
186+
"anthropic_tokenizer.json"
187+
).open("r") as f:
188+
json_data = json.load(f)
189+
except (ImportError, AttributeError, TypeError):
190+
with resources.open_text(
191+
"litellm.litellm_core_utils.tokenizers", "anthropic_tokenizer.json"
192+
) as f:
193+
json_data = json.load(f)
194+
187195
# Convert to str (if necessary)
188196
claude_json_str = json.dumps(json_data)
189197
import importlib.metadata

0 commit comments

Comments
 (0)