Class DefaultContentInjector
java.lang.Object
dev.langchain4j.rag.content.injector.DefaultContentInjector
- All Implemented Interfaces:
ContentInjector
Default implementation of
It's important to note that while efforts will be made to avoid breaking changes, the default behavior of this class may be updated in the future if it's found that the current behavior does not adequately serve the majority of use cases. Such changes would be made to benefit both current and future users.
This implementation appends all given
Configurable parameters (optional):
-
-
ContentInjector
intended to be suitable for the majority of use cases.
It's important to note that while efforts will be made to avoid breaking changes, the default behavior of this class may be updated in the future if it's found that the current behavior does not adequately serve the majority of use cases. Such changes would be made to benefit both current and future users.
This implementation appends all given
Content
s to the end of the given UserMessage
in their order of iteration.
Refer to DEFAULT_PROMPT_TEMPLATE
and implementation for more details.
Configurable parameters (optional):
-
promptTemplate
: The prompt template that defines how the original userMessage
and contents
are combined into the resulting UserMessage
.
The text of the template should contain the {{userMessage}}
and {{contents}}
variables.
-
metadataKeysToInclude
: A list of Metadata
keys that should be included
with each Content.textSegment()
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDefaultContentInjector
(PromptTemplate promptTemplate) DefaultContentInjector
(PromptTemplate promptTemplate, List<String> metadataKeysToInclude) DefaultContentInjector
(List<String> metadataKeysToInclude) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
protected Prompt
createPrompt
(ChatMessage chatMessage, List<Content> contents) protected Prompt
createPrompt
(UserMessage userMessage, List<Content> contents) Deprecated.protected String
protected String
protected String
protected String
inject
(List<Content> contents, ChatMessage chatMessage) Injects givenContent
s into a givenChatMessage
.inject
(List<Content> contents, UserMessage userMessage) Deprecated.useinject(List, ChatMessage)
instead.
-
Field Details
-
DEFAULT_PROMPT_TEMPLATE
-
-
Constructor Details
-
DefaultContentInjector
public DefaultContentInjector() -
DefaultContentInjector
-
DefaultContentInjector
-
DefaultContentInjector
-
-
Method Details
-
builder
-
inject
Description copied from interface:ContentInjector
Injects givenContent
s into a givenChatMessage
.
This method has a default implementation in order to temporarily support current custom implementations ofContentInjector
. The default implementation will be removed soon.- Specified by:
inject
in interfaceContentInjector
- Parameters:
contents
- The list ofContent
to be injected.chatMessage
- TheChatMessage
into which theContent
s are to be injected. Can be either aUserMessage
or aSystemMessage
.- Returns:
- The
UserMessage
with the injectedContent
s.
-
createPrompt
-
inject
Deprecated.useinject(List, ChatMessage)
instead.Description copied from interface:ContentInjector
Injects givenContent
s into a givenUserMessage
.- Specified by:
inject
in interfaceContentInjector
- Parameters:
contents
- The list ofContent
to be injected.userMessage
- TheUserMessage
into which theContent
s are to be injected.- Returns:
- The
UserMessage
with the injectedContent
s.
-
createPrompt
Deprecated.implement/overridecreatePrompt(ChatMessage, List)
instead. -
format
-
format
-
format
-
format
-
createPrompt(ChatMessage, List)
instead.