java.lang.Object
com.google.genkit.plugins.evaluators.metrics.PromptUtils

public class PromptUtils extends Object
Utility class for loading and rendering prompt templates.
  • Method Details

    • loadPrompt

      public static String loadPrompt(String promptName) throws IOException
      Loads a prompt template from the classpath.
      Parameters:
      promptName - the name of the prompt file (without path prefix)
      Returns:
      the prompt template content
      Throws:
      IOException - if the prompt file cannot be read
    • renderPrompt

      public static String renderPrompt(String template, Map<String,String> variables)
      Renders a prompt template by substituting variables.
      Parameters:
      template - the prompt template
      variables - the variables to substitute
      Returns:
      the rendered prompt
    • loadAndRender

      public static String loadAndRender(String promptName, Map<String,String> variables) throws IOException
      Loads and renders a prompt template.
      Parameters:
      promptName - the name of the prompt file
      variables - the variables to substitute
      Returns:
      the rendered prompt
      Throws:
      IOException - if the prompt file cannot be read
    • stringify

      public static String stringify(Object obj)
      Converts an object to a string representation for use in prompts.
      Parameters:
      obj - the object to convert
      Returns:
      the string representation