[Fix] Allow for functions as token_counters in BaseChunkers #70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request includes several changes to the
src/chonkie/chunker/base.py
file to improve the handling of different tokenizer backends and provide more informative error messages. The most important changes include adding theinspect
module to check if an object is a function, updating the initialization logic to handle different types of tokenizers, and enhancing the error messages to include the unsupported tokenizer backend type.Improvements to tokenizer handling:
inspect
module to check if an object is a function. (src/chonkie/chunker/base.py
)__init__
method to first check if thetokenizer_or_token_counter
is a string, then check if it is a function usinginspect.isfunction
, and finally assume it is a tokenizer object if neither condition is met. (src/chonkie/chunker/base.py
)Enhanced error messages:
_get_tokenizer_backend
method to include the unsupported tokenizer backend type in the error message. (src/chonkie/chunker/base.py
)_encode
,_encode_batch
,_decode
, and_decode_batch
methods to include the unsupported tokenizer backend type in the error messages. (src/chonkie/chunker/base.py
) [1] [2] [3] [4]