Class PromptTemplate
java.lang.Object
com.codename1.ai.PromptTemplate
Trivial {placeholder} substitution. Designed for the common
"build a prompt from a handful of fields" pattern without pulling
in a templating library. For anything more sophisticated (loops,
conditionals) just compose strings directly.
String prompt = PromptTemplate.of(
"You are an expert {role}. Reply in {style}."
).put("role", "tax accountant").put("style", "bullet points").build();
-
Method Summary
Modifier and TypeMethodDescriptionasSystem()Convenience: render and wrap as aChatMessagewith SYSTEM role.asUser()Convenience: render and wrap as aChatMessagewith USER role.build()Renders the final string.static PromptTemplateStarts a template instance.Binds one placeholder.Adds all supplied placeholder values.
-
Method Details
-
of
Starts a template instance.- Parameters:
template- text containing optional{name}placeholders- Returns:
- mutable template values bound to the supplied text
-
put
Binds one placeholder. Anullvalue renders as an empty string.- Parameters:
key- placeholder name without bracesvalue- replacement value- Returns:
- this template
-
putAll
Adds all supplied placeholder values.- Parameters:
map- replacements keyed by placeholder name;nullis ignored- Returns:
- this template
-
build
Renders the final string. Unknown placeholders are left intact ({like_this}) so they're easy to spot in test output -- silently dropping them tends to hide bugs.- Returns:
- rendered prompt text
-
asUser
Convenience: render and wrap as aChatMessagewith USER role.- Returns:
- rendered user message
-
asSystem
Convenience: render and wrap as aChatMessagewith SYSTEM role.- Returns:
- rendered system message
-