mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-25 01:02:15 +00:00
refactor(tokenizer): count custom tokenizers directly
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
2d452a01f8
commit
12ca5ac618
1 changed files with 1 additions and 4 deletions
|
|
@ -626,10 +626,7 @@ def _get_exact_count_function(
|
|||
tokenizer: Final[Tokenizer | NativeTokenizer] = tokenizer_json["tokenizer"]
|
||||
|
||||
def count_tokens(text: str) -> int:
|
||||
count: Final = getattr(tokenizer, "count", None)
|
||||
if callable(count):
|
||||
return count(text)
|
||||
return len(tokenizer.encode_batch_fast([text])[0])
|
||||
return tokenizer.count(text)
|
||||
|
||||
return count_tokens
|
||||
elif tokenizer_json["type"] == "openai_tokenizer":
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue