IPromptTemplate
Interfaces · AiDotNet.Interfaces
Defines the contract for prompt templates used in language model interactions.
Known implementations: CompositePromptTemplate, PromptTemplateBase
For Beginners
A prompt template is like a form with blanks to fill in.
Think of it like a mad lib:
- Template: “The {adjective} {noun} {verb} over the {place}.”
- Variables: adjective=“quick”, noun=“fox”, verb=“jumped”, place=“fence”
- Result: “The quick fox jumped over the fence.”
In LLM applications:
- Template: “Translate the following {source_lang} to {target_lang}: {text}”
- Variables: source_lang=“English”, target_lang=“French”, text=“Hello”
- Result: “Translate the following English to French: Hello”
Benefits of using templates:
- Reusability: Write the template once, use it many times
- Consistency: All prompts have the same structure
- Maintainability: Change the template in one place
- Safety: Validate inputs before insertion
- Clarity: Separate prompt logic from data
How It Works
A prompt template provides a structured way to create prompts for language models by combining a template string with runtime variables. Templates support variable substitution, formatting, and composition of complex prompts from reusable components.
Properties
| Property | Summary |
|---|---|
IReadOnlyList<string> InputVariables { get; } |
Gets the list of variable names that this template expects. |
string Template { get; } |
Gets the raw template string before variable substitution. |
Methods
| Method | Summary |
|---|---|
bool Validate(Dictionary<string, string> variables) |
Validates that the provided variables match the template’s requirements. |
string Format(Dictionary<string, string> variables) |
Formats the template with the provided variables to create a complete prompt. |