MCPcopy Index your code
hub / github.com/FSoft-AI4Code/CodeWiki / count_tokens

Function count_tokens

codewiki/src/be/utils.py:53–59  ·  view source on GitHub ↗

Count the number of tokens in a text.

(text: str)

Source from the content-addressed store, hash-verified

51enc = tiktoken.encoding_for_model("gpt-4")
52
53def count_tokens(text: str) -> int:
54 """
55 Count the number of tokens in a text.
56 """
57 length = len(enc.encode(text))
58 # logger.debug(f"Number of tokens: {length}")
59 return length
60
61
62# ------------------------------------------------------------

Callers 4

cluster_modulesFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected