MCPcopy
hub / github.com/openai/tiktoken / load_tiktoken_bpe

Function load_tiktoken_bpe

tiktoken/load.py:159–171  ·  view source on GitHub ↗
(tiktoken_bpe_file: str, expected_hash: str | None = None)

Source from the content-addressed store, hash-verified

157
158
159def load_tiktoken_bpe(tiktoken_bpe_file: str, expected_hash: str | None = None) -> dict[bytes, int]:
160 # NB: do not add caching to this function
161 contents = read_file_cached(tiktoken_bpe_file, expected_hash)
162 ret = {}
163 for line in contents.splitlines():
164 if not line:
165 continue
166 try:
167 token, rank = line.split()
168 ret[base64.b64decode(token)] = int(rank)
169 except Exception as e:
170 raise ValueError(f"Error parsing line {line!r} in {tiktoken_bpe_file}") from e
171 return ret

Callers 5

r50k_baseFunction · 0.90
p50k_baseFunction · 0.90
p50k_editFunction · 0.90
cl100k_baseFunction · 0.90
o200k_baseFunction · 0.90

Calls 1

read_file_cachedFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…