Class SimplePromptTemplate

java.lang.Object
com.tnsai.prompt.SimplePromptTemplate
All Implemented Interfaces:
com.tnsai.prompt.PromptTemplate

public class SimplePromptTemplate extends Object implements com.tnsai.prompt.PromptTemplate
Simple prompt template implementation using the SimpleTemplateEngine.

Usage


 // Create from string
 PromptTemplate template = SimplePromptTemplate.of(
     "code-review",
     "Review this {{language}} code for {{focus}}:\n\n{{code}}"
 );

 // Render with variables
 String prompt = template.render(Map.of(
     "language", "Java",
     "focus", "security vulnerabilities",
     "code", codeSnippet
 ));

 // With metadata
 PromptTemplate template = SimplePromptTemplate.builder("summarize")
     .content("Summarize the following text in {{style}} style:\n\n{{text}}")
     .metadata(PromptSpec.builder()
         .version("1.0.0")
         .requiredVariables("text")
         .build())
     .build();
 
  • Method Details

    • of

      public static SimplePromptTemplate of(String name, String content)
      Creates a simple template with name and content.
      Parameters:
      name - the template name
      content - the template content
      Returns:
      new template
    • builder

      public static SimplePromptTemplate.Builder builder(String name)
      Creates a builder for templates.
      Parameters:
      name - the template name
      Returns:
      new builder
    • getName

      public String getName()
      Specified by:
      getName in interface com.tnsai.prompt.PromptTemplate
    • getContent

      public String getContent()
      Specified by:
      getContent in interface com.tnsai.prompt.PromptTemplate
    • render

      public String render(Map<String,Object> variables)
      Specified by:
      render in interface com.tnsai.prompt.PromptTemplate
    • getVariables

      public Set<String> getVariables()
      Specified by:
      getVariables in interface com.tnsai.prompt.PromptTemplate
    • getSpec

      public com.tnsai.prompt.PromptSpec getSpec()
      Specified by:
      getSpec in interface com.tnsai.prompt.PromptTemplate
    • toString

      public String toString()
      Overrides:
      toString in class Object