mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-07-15 21:11:05 +02:00
12 lines
352 B
Python
12 lines
352 B
Python
|
|
# pageindex/tokens.py
|
||
|
|
# Leaf utility so both the parser and index layers can count tokens without
|
||
|
|
# the parser reaching back into pageindex.index (a reverse/horizontal
|
||
|
|
# dependency). Depends only on litellm.
|
||
|
|
import litellm
|
||
|
|
|
||
|
|
|
||
|
|
def count_tokens(text, model=None):
|
||
|
|
if not text:
|
||
|
|
return 0
|
||
|
|
return litellm.token_counter(model=model, text=text)
|