pub struct PromptTemplate {
pub name: String,
pub version: String,
pub system: Option<String>,
pub body: String,
pub variables: HashMap<String, Option<String>>,
pub tags: Vec<String>,
pub description: Option<String>,
}Expand description
A versioned prompt template with variable placeholders.
Placeholders use {{variable_name}} syntax. Variables are resolved at
render time from a caller-supplied map. Missing variables default to the
empty string unless a default is configured on the template.
Fields§
§name: StringUnique template name used as the lookup key.
version: StringSemantic version string (e.g. "v1", "v2.1").
system: Option<String>Optional system prompt (sent as the first turn or prefixed).
body: StringTemplate body with {{variable}} placeholders.
variables: HashMap<String, Option<String>>Variable names declared in this template with optional defaults.
Arbitrary tags for grouping and filtering.
description: Option<String>Human-readable description.
Implementations§
Source§impl PromptTemplate
impl PromptTemplate
Sourcepub fn builder(name: impl Into<String>) -> TemplateBuilder
pub fn builder(name: impl Into<String>) -> TemplateBuilder
Start building a template with the given name.
Sourcepub fn render(&self, vars: &HashMap<&str, &str>) -> String
pub fn render(&self, vars: &HashMap<&str, &str>) -> String
Render the template body by substituting vars for each {{key}}.
In addition to simple {{variable}} interpolation this method handles:
-
Conditional blocks
{{#if condition}}...{{/if}}— the block is included ifvarscontains a key equal toconditionwhose value is non-empty and not the literal string"false"or"0". -
Loop blocks
{{#each items}}...{{/each}}— the block is repeated once for each item in a comma-separated list stored under the keyitems. Inside the block{{this}}is replaced with the current item and{{@index}}with the zero-based index.
Variables present in the template but absent from vars fall back to
the template’s own default value. If no default exists the placeholder
is replaced with an empty string.
Sourcepub fn render_full(
&self,
vars: &HashMap<&str, &str>,
) -> (Option<String>, String)
pub fn render_full( &self, vars: &HashMap<&str, &str>, ) -> (Option<String>, String)
Render both system prompt (if any) and body; returns (system, body).
Sourcepub fn declared_variables(&self) -> Vec<String>
pub fn declared_variables(&self) -> Vec<String>
Extract variable names declared in the body ({{name}}).
Trait Implementations§
Source§impl Clone for PromptTemplate
impl Clone for PromptTemplate
Source§fn clone(&self) -> PromptTemplate
fn clone(&self) -> PromptTemplate
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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 UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request