Class DecisionModelInputUtils
java.lang.Object
dev.langchain4j.internal.DecisionModelInputUtils
Converts chat messages into the input of a
DecisionModel, the same way for
all components that use one.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA conversation as one map per message, and the images it refers to, in order. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanhasText(UserMessage userMessage) Whether the user message contains text, not only other content such as images.static Stringtext(ChatMessage message) The text of a user or assistant message.transcript(List<ChatMessage> messages) A conversation as a transcript, seetranscript(List, String).transcript(List<ChatMessage> messages, String provider) A conversation as a transcript: one map per message, with the images of the conversation referred to by their position, for example[image 1].static StringShortens a text longer thanmaxLengthcharacters by keeping its beginning (two thirds) and its end (one third), with a note of about 90 characters in between saying how many characters were left out.static List<ChatMessage> window(List<ChatMessage> messages, Predicate<? super ChatMessage> filter, int maxMessages, int maxMessageLength) The messages a decision model receives about a conversation: the system messages that pass the filter, and the lastmaxMessagesother messages that pass the filter, without the tool results at their start whose AI message is not among them, plus the last user message if it is older (unlessmaxMessagesis 0).
-
Method Details
-
text
The text of a user or assistant message. Content of a user message other than text is represented by a marker, such as[attached image]. Other messages, and assistant messages without text, give an empty string. -
hasText
Whether the user message contains text, not only other content such as images. -
window
public static List<ChatMessage> window(List<ChatMessage> messages, Predicate<? super ChatMessage> filter, int maxMessages, int maxMessageLength) The messages a decision model receives about a conversation: the system messages that pass the filter, and the lastmaxMessagesother messages that pass the filter, without the tool results at their start whose AI message is not among them, plus the last user message if it is older (unlessmaxMessagesis 0). Contents other than text are replaced by a marker, such as[attached image]. The text of messages other than system messages, and the arguments of tool calls, that are longer thanmaxMessageLengthcharacters are shortened in the middle (seetruncate(String, int)). Custom messages, and AI messages with neither text nor tool calls, are left out. -
truncate
Shortens a text longer thanmaxLengthcharacters by keeping its beginning (two thirds) and its end (one third), with a note of about 90 characters in between saying how many characters were left out. A text that would not get shorter is returned as it is. The note says that the assistant saw the full text, so that a decision model does not take the missing part as missing information: in tests, a plain marker made decision models reject answers that were based on the full text. -
transcript
public static DecisionModelInputUtils.Transcript transcript(List<ChatMessage> messages, String provider) A conversation as a transcript: one map per message, with the images of the conversation referred to by their position, for example[image 1]. Decision models without native support for conversations send it as JSON. The thinking of assistant messages is left out, and assistant messages with neither text nor tool calls are skipped.- Parameters:
provider- the name of the decision model, used in error messages.- Throws:
UnsupportedFeatureException- if a message or a content is neither text nor an image.IllegalArgumentException- if nothing is left to send.
-
transcript
A conversation as a transcript, seetranscript(List, String).
-