Skip to main content

Module templates

Module templates 

Source
Expand description

§Prompt Template Engine

Versioned, variable-interpolated prompt templates with built-in A/B testing.

§Overview

  • Templates — named prompt blueprints with {{variable}} placeholders, optional system prompts, and version tags.
  • Registry — hot-reloadable store for all templates; load from TOML.
  • A/B Experiments — route traffic between template variants, collect per-variant latency and quality metrics, and determine winners via a two-proportion Z-test.

§Quick start

use tokio_prompt_orchestrator::templates::{PromptTemplate, TemplateRegistry};
use std::collections::HashMap;

let registry = TemplateRegistry::new();

let t = PromptTemplate::builder("summarise")
    .version("v2")
    .system("You are a concise summariser.")
    .body("Summarise the following in {{max_words}} words or fewer:\n\n{{text}}")
    .tag("summarisation")
    .build();

registry.register(t);

let mut vars = HashMap::new();
vars.insert("max_words", "50");
vars.insert("text", "The quick brown fox…");

let rendered = registry.render("summarise", &vars).unwrap();
println!("{rendered}");

Structs§

AbExperiment
An A/B experiment that routes traffic between template variants.
ExperimentReport
A point-in-time report for an A/B experiment.
ExperimentVariant
A single variant in an A/B experiment.
PromptTemplate
A versioned prompt template with variable placeholders.
TemplateBuilder
Fluent builder for PromptTemplate.
TemplateRegistry
Thread-safe registry of named prompt templates.
VariantMetrics
Metrics collected per A/B variant.
VariantReport

Enums§

TemplateError
Template lookup errors.