Package com.tnsai.prompt
Interface PromptTemplate
public interface PromptTemplate
Interface for prompt templates with variable substitution.
Prompt templates allow externalized prompt management with support for variables, partials, and versioning.
Usage
// Load from registry
PromptTemplate template = PromptRegistry.get("agents/reviewer");
// Render with variables
String prompt = template.render(Map.of(
"task", "Review this code for security issues",
"context", codeSnippet
));
// Check metadata
System.out.println("Version: " + template.getSpec().version());
-
Method Summary
Modifier and TypeMethodDescriptionGets the raw template content before variable substitution.getName()Gets the template name/identifier.getSpec()Gets the template metadata.Gets the set of variable names used in this template.default booleanhasAllVariables(Map<String, Object> variables) Returns whether all required variables are provided.default Stringrender()Renders the template with no variables.Renders the template with the given variables.default voidvalidateVariables(Map<String, Object> variables) Validates that all required variables are provided.
-
Method Details
-
getName
String getName()Gets the template name/identifier.- Returns:
- template name
-
getContent
String getContent()Gets the raw template content before variable substitution.- Returns:
- raw template content
-
render
Renders the template with the given variables.- Parameters:
variables- map of variable names to values- Returns:
- rendered prompt string
-
render
Renders the template with no variables.- Returns:
- rendered prompt string
-
getVariables
Gets the set of variable names used in this template.- Returns:
- set of variable names
-
getSpec
PromptSpec getSpec()Gets the template metadata.- Returns:
- metadata
-
hasAllVariables
Returns whether all required variables are provided.- Parameters:
variables- the provided variables- Returns:
- true if all required variables are present
-
validateVariables
Validates that all required variables are provided.- Parameters:
variables- the provided variables- Throws:
PromptException- if required variables are missing
-