Skip to content

Commit

Permalink
[Fix] Add tiktoken dependency in 'all' + check for it in OpenAIEmebdd…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
bhavnicksm committed Feb 25, 2025
1 parent 7504977 commit 7a4bcb7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ all = [
"sentence-transformers>=3.0.0",
"numpy>=1.23.0, <2.2",
"openai>=1.0.0",
"tiktoken>=0.5.0",
"model2vec>=0.3.0",
"cohere>=5.13.0"
]
Expand Down
9 changes: 7 additions & 2 deletions src/chonkie/embeddings/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(
super().__init__()
if not self.is_available():
raise ImportError(
"OpenAI package is not available. Please install it via `pip install chonkie[openai]`"
"One (or more) of the following packages is not available: openai, numpy, tiktoken. Please install it via `pip install "chonkie[openai]"`"
)

if model not in self.AVAILABLE_MODELS:
Expand Down Expand Up @@ -169,7 +169,12 @@ def get_tokenizer_or_token_counter(self):
@classmethod
def is_available(cls) -> bool:
"""Check if the OpenAI package is available."""
return importutil.find_spec("openai") is not None
# We should check for OpenAI package alongside Numpy and tiktoken
return (
importutil.find_spec("openai") is not None
and importutil.find_spec("numpy") is not None
and importutil.find_spec("tiktoken") is not None
)

def __repr__(self) -> str:
"""Representation of the OpenAIEmbeddings instance."""
Expand Down

0 comments on commit 7a4bcb7

Please sign in to comment.