Codec
Convert text and conversations into the token representation used by a policy.
ChatCodec
Section titled “ChatCodec”Turn text and chat messages into tokens using a tokenizer and its chat template.
The tokenizer needs a chat template to render a conversation. encode() and decode() convert plain text to and from token IDs.
Definition
ChatCodec.init
Section titled “ChatCodec.init”ChatCodec.tokenizer
Section titled “ChatCodec.tokenizer”The tokenizer used to encode text and render conversations.
ChatCodec.supports_chat
Section titled “ChatCodec.supports_chat”Whether the tokenizer provides the chat template needed to render conversations.
ChatCodec.encode
Section titled “ChatCodec.encode”Convert a text fragment to token IDs. add_special_tokens=False by default, so a fragment can extend an existing prefix; render() adds the chat-template tokens when formatting the conversation.
ChatCodec.decode
Section titled “ChatCodec.decode”ChatCodec.render
Section titled “ChatCodec.render”Render the full conversation and OpenAI-style function schemas through the tokenizer’s chat template. Raises ValueError if the tokenizer has no chat template.
HFTokenizer
Section titled “HFTokenizer”Specify the tokenizer operations required by ChatCodec, including encoding, decoding, and chat-template application. A compatible tokenizer can implement this protocol without inheriting from it.
Definition
Fields
HFTokenizer.encode
Section titled “HFTokenizer.encode”HFTokenizer.decode
Section titled “HFTokenizer.decode”HFTokenizer.apply_chat_template
Section titled “HFTokenizer.apply_chat_template”Message
Section titled “Message”A dictionary representing a chat message, such as a user prompt, assistant reply, or tool observation. Its fields follow the conversation format used by the policy.
Definition
TextCodec
Section titled “TextCodec”The minimal tokenizer interface: convert text to token IDs and token IDs back to text. Implement it when adapting a tokenizer for a backend.
Definition