pub struct PromptTemplate { /* private fields */ }Expand description
A prompt template with variable placeholders.
Variables are denoted with double curly braces: {{variable_name}}
Implementations§
Source§impl PromptTemplate
impl PromptTemplate
Sourcepub fn has_variables(&self) -> bool
pub fn has_variables(&self) -> bool
Check if this template has any variables.
Sourcepub fn render(&self, values: &HashMap<String, String>) -> Result<String>
pub fn render(&self, values: &HashMap<String, String>) -> Result<String>
Render the template with the given values.
§Errors
Returns an error if any required variable is missing from the values map.
§Example
ⓘ
let template = PromptTemplate::new("Hello, {{name}}!");
let mut values = HashMap::new();
values.insert("name".to_string(), "World".to_string());
assert_eq!(template.render(&values)?, "Hello, World!");Sourcepub fn render_with_defaults(
&self,
values: &HashMap<String, String>,
defaults: &HashMap<String, String>,
) -> String
pub fn render_with_defaults( &self, values: &HashMap<String, String>, defaults: &HashMap<String, String>, ) -> String
Render the template, using defaults for missing variables.
Variables not in values will be replaced with empty string or
their value from defaults if provided.
Trait Implementations§
Source§impl Clone for PromptTemplate
impl Clone for PromptTemplate
Source§fn clone(&self) -> PromptTemplate
fn clone(&self) -> PromptTemplate
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PromptTemplate
impl RefUnwindSafe for PromptTemplate
impl Send for PromptTemplate
impl Sync for PromptTemplate
impl Unpin for PromptTemplate
impl UnwindSafe for PromptTemplate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more