From aa78f55dff43835f3bdbbd41584837fd4ed71dbe Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Thu, 15 Feb 2024 17:57:23 -0800 Subject: [PATCH] fix(utils.py): add try-except around the tiktoken local import --- litellm/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index 018308e56..35bf4640f 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -34,7 +34,14 @@ from dataclasses import ( from importlib import resources # filename = pkg_resources.resource_filename(__name__, "llms/tokenizers") -filename = str(resources.files(litellm).joinpath("llms/tokenizers")) +try: + filename = str( + resources.files().joinpath("llms/tokenizers") # type: ignore + ) # for python 3.8 and 3.12 +except: + filename = str( + resources.files(litellm).joinpath("llms/tokenizers") # for python 3.10 + ) # for python 3.10+ os.environ[ "TIKTOKEN_CACHE_DIR" ] = filename # use local copy of tiktoken b/c of - https://github.com/BerriAI/litellm/issues/1071