Update docs to mention NoOpTemplateRenderer
This commit is contained in:
@@ -179,9 +179,15 @@ String answer = ChatClient.create(chatModel).prompt()
|
||||
.content();
|
||||
----
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
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]).
|
||||
Spring AI also provides a `NoOpTemplateRenderer` for cases where no template processing is desired.
|
||||
|
||||
Spring AI also provides a `NoOpTemplateRenderer`.
|
||||
|
||||
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]).
|
||||
|
||||
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.
|
||||
|
||||
|
||||
@@ -141,6 +141,24 @@ public interface TemplateRenderer extends BiFunction<String, Map<String, Object>
|
||||
}
|
||||
----
|
||||
|
||||
Spring AI uses the `TemplateRenderer` interface to handle the actual substitution of variables into the template string.
|
||||
The default implementation uses <<StringTemplate>>.
|
||||
You can provide your own implementation of `TemplateRenderer` if you need custom logic.
|
||||
For scenarios where no template rendering is required (e.g., the template string is already complete), you can use the provided `NoOpTemplateRenderer`.
|
||||
|
||||
.Example using a custom StringTemplate renderer with '<' and '>' delimiters
|
||||
[source,java]
|
||||
----
|
||||
PromptTemplate promptTemplate = PromptTemplate.builder()
|
||||
.renderer(StTemplateRenderer.builder().startDelimiterToken('<').endDelimiterToken('>').build())
|
||||
.template("""
|
||||
Tell me the names of 5 movies whose soundtrack was composed by <composer>.
|
||||
""")
|
||||
.build();
|
||||
|
||||
String prompt = promptTemplate.render(Map.of("composer", "John Williams"));
|
||||
----
|
||||
|
||||
The interfaces implemented by this class support different aspects of prompt creation:
|
||||
|
||||
`PromptTemplateStringActions` focuses on creating and rendering prompt strings, representing the most basic form of prompt generation.
|
||||
|
||||
Reference in New Issue
Block a user