MCPcopy Create free account
hub / github.com/KnowledgeXLab/LeanRAG / encode_string_by_tiktoken

Function encode_string_by_tiktoken

tools/_utils.py:120–125  ·  view source on GitHub ↗
(content: str, model_name: str = "gpt-4o")

Source from the content-addressed store, hash-verified

118
119
120def encode_string_by_tiktoken(content: str, model_name: str = "gpt-4o"):
121 global ENCODER
122 if ENCODER is None:
123 ENCODER = tiktoken.encoding_for_model(model_name)
124 tokens = ENCODER.encode(content)
125 return tokens
126
127
128def decode_tokens_by_tiktoken(tokens: list[int], model_name: str = "gpt-4o"):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected