Skip to content

Commit 435cf13

Browse files
committed
Update docs to mention NoOpTemplateRenderer
1 parent 5527d03 commit 435cf13

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chatclient.adoc

+8-2
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,15 @@ String answer = ChatClient.create(chatModel).prompt()
179179
.content();
180180
----
181181

182-
Internally, the ChatClient uses the `PromptTemplate` class to handle the user and system text and replace the variables with the values provided at runtime relying on a given `TemplateRenderer` implementation. By default, Spring AI uses the `StTemplateRenderer` implementation, which is based on the open-source https://www.stringtemplate.org/[StringTemplate] engine developed by Terence Parr.
182+
Internally, the ChatClient uses the `PromptTemplate` class to handle the user and system text and replace the variables with the values provided at runtime relying on a given `TemplateRenderer` implementation.
183+
By default, Spring AI uses the `StTemplateRenderer` implementation, which is based on the open-source https://www.stringtemplate.org/[StringTemplate] engine developed by Terence Parr.
183184

184-
NOTE: The `TemplateRenderer` configured directly on the `ChatClient` (via `.templateRenderer()`) applies only to the prompt content defined directly in the `ChatClient` builder chain (e.g., via `.user()`, `.system()`). It does *not* affect templates used internally by xref:api/retrieval-augmented-generation.adoc#_questionansweradvisor[Advisors] like `QuestionAnswerAdvisor`, which have their own template customization mechanisms (see xref:api/retrieval-augmented-generation.adoc#_custom_template[Custom Advisor Templates]).
185+
Spring AI also provides a `NoOpTemplateRenderer` for cases where no template processing is desired.
186+
187+
Spring AI also provides a `NoOpTemplateRenderer`.
188+
189+
NOTE: The `TemplateRenderer` configured directly on the `ChatClient` (via `.templateRenderer()`) applies only to the prompt content defined directly in the `ChatClient` builder chain (e.g., via `.user()`, `.system()`).
190+
It does *not* affect templates used internally by xref:api/retrieval-augmented-generation.adoc#_questionansweradvisor[Advisors] like `QuestionAnswerAdvisor`, which have their own template customization mechanisms (see xref:api/retrieval-augmented-generation.adoc#_custom_template[Custom Advisor Templates]).
185191

186192
If you'd rather use a different template engine, you can provide a custom implementation of the `TemplateRenderer` interface directly to the ChatClient. You can also keep using the default `StTemplateRenderer`, but with a custom configuration.
187193

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/prompt.adoc

+18
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,24 @@ public interface TemplateRenderer extends BiFunction<String, Map<String, Object>
141141
}
142142
----
143143

144+
Spring AI uses the `TemplateRenderer` interface to handle the actual substitution of variables into the template string.
145+
The default implementation uses <<StringTemplate>>.
146+
You can provide your own implementation of `TemplateRenderer` if you need custom logic.
147+
For scenarios where no template rendering is required (e.g., the template string is already complete), you can use the provided `NoOpTemplateRenderer`.
148+
149+
.Example using a custom StringTemplate renderer with '<' and '>' delimiters
150+
[source,java]
151+
----
152+
PromptTemplate promptTemplate = PromptTemplate.builder()
153+
.renderer(StTemplateRenderer.builder().startDelimiterToken('<').endDelimiterToken('>').build())
154+
.template("""
155+
Tell me the names of 5 movies whose soundtrack was composed by <composer>.
156+
""")
157+
.build();
158+
159+
String prompt = promptTemplate.render(Map.of("composer", "John Williams"));
160+
----
161+
144162
The interfaces implemented by this class support different aspects of prompt creation:
145163

146164
`PromptTemplateStringActions` focuses on creating and rendering prompt strings, representing the most basic form of prompt generation.

0 commit comments

Comments
 (0)