Skip to content

Commit 28d3734

Browse files
committed
fix: count literal special tokens like <|endoftext|> as plain text
Repos that vendor tokenizer code (e.g. CLIP) contain the literal string '<|endoftext|>'. tiktoken rejects it by default, so count_tokens raised and module clustering aborted before any LLM call.
1 parent 64c2b60 commit 28d3734

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎codewiki/src/be/utils.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def count_tokens(text: str) -> int:
5656
"""
5757
Count the number of tokens in a text.
5858
"""
59-
length = len(enc.encode(text))
59+
# source code may contain literal special tokens such as "<|endoftext|>"
60+
# (e.g. CLIP tokenizers); count them as plain text instead of raising
61+
length = len(enc.encode(text, disallowed_special=()))
6062
# logger.debug(f"Number of tokens: {length}")
6163
return length
6264

0 commit comments

Comments
 (0)