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;
// Common types have ToPrompt implementations
let number = 42;
assert_eq!(number.to_prompt(), "42");
let text = "Hello, LLM!";
assert_eq!(text.to_prompt(), "Hello, LLM!");§Custom Implementation
You can also implement ToPrompt directly 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)
}
}
// By implementing ToPrompt directly, you can control the conversion.
impl ToPrompt for CustomType {
fn to_prompt(&self) -> String {
self.to_string()
}
}
let custom = CustomType { value: "custom".to_string() };
assert_eq!(custom.to_prompt(), "custom");