pub struct TemplateRegistry { /* private fields */ }Expand description
Thread-safe registry of named prompt templates.
Cheap to clone (Arc-backed). The registry supports hot-reload: call
register to add or replace a template at any time.
Implementations§
Source§impl TemplateRegistry
impl TemplateRegistry
pub fn new() -> Self
Sourcepub fn register(&self, template: PromptTemplate)
pub fn register(&self, template: PromptTemplate)
Register (or replace) a template.
Sourcepub fn unregister(&self, name: &str)
pub fn unregister(&self, name: &str)
Remove a template by name.
Sourcepub fn render(
&self,
name: &str,
vars: &HashMap<&str, &str>,
) -> Result<String, TemplateError>
pub fn render( &self, name: &str, vars: &HashMap<&str, &str>, ) -> Result<String, TemplateError>
Render a named template with the supplied variables.
Sourcepub fn render_full(
&self,
name: &str,
vars: &HashMap<&str, &str>,
) -> Result<(Option<String>, String), TemplateError>
pub fn render_full( &self, name: &str, vars: &HashMap<&str, &str>, ) -> Result<(Option<String>, String), TemplateError>
Render a template and return (system_prompt, body).
Sourcepub fn get(&self, name: &str) -> Option<PromptTemplate>
pub fn get(&self, name: &str) -> Option<PromptTemplate>
Get a snapshot of a template (cloned).
Sourcepub fn load_toml(&self, toml_str: &str) -> Result<usize, String>
pub fn load_toml(&self, toml_str: &str) -> Result<usize, String>
Load templates from a TOML string.
Expected format:
[[templates]]
name = "summarise"
version = "v1"
system = "You are a summariser."
body = "Summarise: {{text}}"
tags = ["nlp"]
[[templates]]
name = "translate"
body = "Translate to {{lang}}: {{text}}"Trait Implementations§
Source§impl Clone for TemplateRegistry
impl Clone for TemplateRegistry
Source§fn clone(&self) -> TemplateRegistry
fn clone(&self) -> TemplateRegistry
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for TemplateRegistry
impl Default for TemplateRegistry
Source§fn default() -> TemplateRegistry
fn default() -> TemplateRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for TemplateRegistry
impl RefUnwindSafe for TemplateRegistry
impl Send for TemplateRegistry
impl Sync for TemplateRegistry
impl Unpin for TemplateRegistry
impl UnsafeUnpin for TemplateRegistry
impl UnwindSafe for TemplateRegistry
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
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>
Wrap the input message
T in a tonic::Request