Class ChatMessageTexts
java.lang.Object
dev.langchain4j.test.internal.ChatMessageTexts
Describes chat messages as text, for judges and failure messages.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classNumbers the contents that are not text, per type, for example[image 1],[image 2]and[pdf 1].static interfaceReceives the parts of a message in their order: its text, and the contents that are not text, such as images. -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringdescribe(List<? extends ChatMessage> messages) Describes the messages, one per line (\n, the same on every operating system), each starting with its role.static Stringdescribe(List<? extends ChatMessage> messages, int maxTextLength) Describes the messages likedescribe(List), cutting the text of each message to the given length.static ChatMessageforJudge(ChatMessage message) Returns the message to send to a judge model, with its contents changed byforJudge(Content).static ContentReturns the content to send to a judge model: an image whose detail level was not chosen when it was created (seeImageContent.detailLevelSpecified()) is copied withImageContent.DetailLevel.AUTO; any other content is returned as it is.static Stringrole(ChatMessage message) Returns who sent the message:system,user,assistant,toolorcustom.static Stringtext(ChatMessage message) Returns the text of the message.static StringReturns the text, cut to the given length, followed by how many characters were cut, for example...(250 more characters).static StringuserText(ChatMessage message) Returns the text of the user messages, ornullfor another message.static voidwrite(ChatMessage message, ChatMessageTexts.PartWriter writer) Writes the parts of the message in their order: the same text astext(ChatMessage), with each content that is not text given toChatMessageTexts.PartWriter.media(Content)at its position instead of being described.
-
Method Details
-
role
Returns who sent the message:system,user,assistant,toolorcustom. -
text
Returns the text of the message. Contents that are not text, such as images, are described by their type, for example[image]. The tool calls of an assistant message are described by the tool name, the call id (when there is one) and the arguments, and the result of a tool execution starts with the tool name and the call id (and says when it is an error), so that several calls of the same tool can be told apart. -
write
Writes the parts of the message in their order: the same text astext(ChatMessage), with each content that is not text given toChatMessageTexts.PartWriter.media(Content)at its position instead of being described. -
forJudge
Returns the content to send to a judge model: an image whose detail level was not chosen when it was created (seeImageContent.detailLevelSpecified()) is copied withImageContent.DetailLevel.AUTO; any other content is returned as it is. -
forJudge
Returns the message to send to a judge model, with its contents changed byforJudge(Content). A message without such contents is returned as it is. -
userText
Returns the text of the user messages, ornullfor another message. -
describe
Describes the messages, one per line (\n, the same on every operating system), each starting with its role. Contents that are not text are shown by numbered markers, for example[image 1], the same way aChatModelJudgemarks them for the judge model. -
describe
Describes the messages likedescribe(List), cutting the text of each message to the given length. -
truncate
-