ToPrompt

Trait ToPrompt 

Source
pub trait ToPrompt {
    // Required method
    fn to_prompt(&self) -> String;
}
Expand description

A trait for converting any type into a string suitable for an LLM prompt.

This trait provides a standard interface for converting various types into strings that can be used as prompts for language models.

§Example

use llm_toolkit::prompt::ToPrompt;

// Any type implementing Display automatically gets ToPrompt
let number = 42;
assert_eq!(number.to_prompt(), "42");

let text = "Hello, LLM!";
assert_eq!(text.to_prompt(), "Hello, LLM!");

§Custom Implementation

While a blanket implementation is provided for all types that implement Display, you can provide custom implementations for your own types:

use llm_toolkit::prompt::ToPrompt;
use std::fmt;

struct CustomType {
    value: String,
}

impl fmt::Display for CustomType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.value)
    }
}

// The blanket implementation provides ToPrompt automatically
let custom = CustomType { value: "custom".to_string() };
assert_eq!(custom.to_prompt(), "custom");

Required Methods§

Source

fn to_prompt(&self) -> String

Converts the object into a prompt string.

Implementors§

Source§

impl<T: Display> ToPrompt for T

A blanket implementation of ToPrompt for any type that implements Display.

This provides automatic ToPrompt functionality for all standard library types and custom types that implement Display.