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

Method decode

tiktoken/core.py:275–287  ·  view source on GitHub ↗

Decodes a list of tokens into a string. WARNING: the default behaviour of this function is lossy, since decoded bytes are not guaranteed to be valid UTF-8. You can control this behaviour using the `errors` parameter, for instance, setting `errors=strict`. ```

(self, tokens: Sequence[int], errors: str = "replace")

Source from the content-addressed store, hash-verified

273 return self._core_bpe.decode_bytes(tokens)
274
275 def decode(self, tokens: Sequence[int], errors: str = "replace") -> str:
276 """Decodes a list of tokens into a string.
277
278 WARNING: the default behaviour of this function is lossy, since decoded bytes are not
279 guaranteed to be valid UTF-8. You can control this behaviour using the `errors` parameter,
280 for instance, setting `errors=strict`.
281
282 ```
283 >>> enc.decode([31373, 995])
284 'hello world'
285 ```
286 """
287 return self._core_bpe.decode_bytes(tokens).decode("utf-8", errors=errors)
288
289 def decode_single_token_bytes(self, token: int) -> bytes:
290 """Decodes a token into bytes.

Callers 11

_token_offsets_referenceFunction · 0.45
test_hyp_offsetsFunction · 0.45
test_simpleFunction · 0.45
test_basic_roundtripFunction · 0.45
test_hyp_roundtripFunction · 0.45
test_simpleFunction · 0.45
encode_ordinaryMethod · 0.45
encodeMethod · 0.45
decode_with_offsetsMethod · 0.45

Calls 1

decode_bytesMethod · 0.45

Tested by 7

_token_offsets_referenceFunction · 0.36
test_hyp_offsetsFunction · 0.36
test_simpleFunction · 0.36
test_basic_roundtripFunction · 0.36
test_hyp_roundtripFunction · 0.36
test_simpleFunction · 0.36