Class PromptUtils
java.lang.Object
com.google.genkit.plugins.evaluators.metrics.PromptUtils
Utility class for loading and rendering prompt templates.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringloadAndRender(String promptName, Map<String, String> variables) Loads and renders a prompt template.static StringloadPrompt(String promptName) Loads a prompt template from the classpath.static StringrenderPrompt(String template, Map<String, String> variables) Renders a prompt template by substituting variables.static StringConverts an object to a string representation for use in prompts.
-
Method Details
-
loadPrompt
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
Renders a prompt template by substituting variables.- Parameters:
template- the prompt templatevariables- the variables to substitute- Returns:
- the rendered prompt
-
loadAndRender
public static String loadAndRender(String promptName, Map<String, String> variables) throws IOExceptionLoads and renders a prompt template.- Parameters:
promptName- the name of the prompt filevariables- the variables to substitute- Returns:
- the rendered prompt
- Throws:
IOException- if the prompt file cannot be read
-
stringify
Converts an object to a string representation for use in prompts.- Parameters:
obj- the object to convert- Returns:
- the string representation
-