Skip to main content

PromptEncoding

Trait PromptEncoding 

Source
pub trait PromptEncoding {
    // Required methods
    fn encode(
        &self,
        conversation: &Conversation,
    ) -> Result<Vec<u32>, EncodingError>;
    fn render_conversation(&self, conversation: &Conversation) -> RenderedPrompt;
}
Expand description

Render model prompts and encode conversations into token IDs.

Required Methods§

Source

fn encode(&self, conversation: &Conversation) -> Result<Vec<u32>, EncodingError>

Encode a conversation into model token IDs using the attached tokenizer.

The tokenizer must be attached to the encoding before this call, through the encoding’s with_tokenizer method. Returns EncodingError::MissingTokenizer when no tokenizer is attached.

Source

fn render_conversation(&self, conversation: &Conversation) -> RenderedPrompt

Render the conversation and the prefix for the next assistant turn.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: EncodingV4> PromptEncoding for T