类 UserMessage
java.lang.Object
dev.langchain4j.data.message.UserMessage
- 所有已实现的接口:
ChatMessage
Represents a message from a user, typically an end user of the application.
Depending on the supported modalities (text, image, audio, video, etc.) of the model, user messages can contain either a single text (a
Optionally, user message can contain a
Depending on the supported modalities (text, image, audio, video, etc.) of the model, user messages can contain either a single text (a
String) or multiple Contents,
which can be either TextContent or ImageContent.
In the future, the list of Content types will expand to allow for more modalities (e.g. audio, video, etc.).
Optionally, user message can contain a
name of the user.
Be aware that not all models support names in UserMessage.-
构造器概要
构造器构造器说明UserMessage(Content... contents) Creates aUserMessagefrom one or multipleContents.UserMessage(String text) Creates aUserMessagefrom a text.UserMessage(String name, Content... contents) Creates aUserMessagefrom a name and one or multipleContents.UserMessage(String name, String text) Creates aUserMessagefrom a name and a text.UserMessage(String name, List<Content> contents) Creates aUserMessagefrom a name and a list ofContents.UserMessage(List<Content> contents) Creates aUserMessagefrom a list ofContents. -
方法概要
修饰符和类型方法说明contents()The contents of the message.booleanstatic UserMessageCreate aUserMessagefrom contents.static UserMessageCreate aUserMessagefrom a text.static UserMessageCreate aUserMessagefrom a name and contents.static UserMessageCreate aUserMessagefrom a name and a text.static UserMessageCreate aUserMessagefrom a name and contents.static UserMessageCreate aUserMessagefrom contents.inthashCode()booleanWhether this message contains a singleTextContent.name()The name of the user.Returns text from a singleTextContent.text()已过时。toString()type()The type of the message.static UserMessageuserMessage(Content... contents) Create aUserMessagefrom contents.static UserMessageuserMessage(String text) Create aUserMessagefrom a text.static UserMessageuserMessage(String name, Content... contents) Create aUserMessagefrom a name and contents.static UserMessageuserMessage(String name, String text) Create aUserMessagefrom a name and a text.static UserMessageuserMessage(String name, List<Content> contents) Create aUserMessagefrom a name and contents.static UserMessageuserMessage(List<Content> contents) Create aUserMessagefrom contents.
-
构造器详细资料
-
UserMessage
Creates aUserMessagefrom a text.- 参数:
text- the text.
-
UserMessage
Creates aUserMessagefrom a name and a text.- 参数:
name- the name.text- the text.
-
UserMessage
Creates aUserMessagefrom one or multipleContents.Contentcan be eitherTextContentorImageContent.
Will have anullname.- 参数:
contents- the contents.
-
UserMessage
Creates aUserMessagefrom a name and one or multipleContents.Contentcan be eitherTextContentorImageContent.- 参数:
name- the name.contents- the contents.
-
UserMessage
Creates aUserMessagefrom a list ofContents.Contentcan be eitherTextContentorImageContent.
Will have anullname.- 参数:
contents- the contents.
-
UserMessage
Creates aUserMessagefrom a name and a list ofContents.Contentcan be eitherTextContentorImageContent.- 参数:
name- the name.contents- the contents.
-
-
方法详细资料
-
name
The name of the user.- 返回:
- the name, or
nullif not set.
-
contents
- 返回:
- the contents.
-
singleText
Returns text from a singleTextContent. Use this accessor only if you are certain that the message contains only a single text. If the message contains multipleContents, or if the onlyContentis not aTextContent, aRuntimeExceptionis thrown.- 返回:
- a single text.
- 另请参阅:
-
hasSingleText
public boolean hasSingleText()Whether this message contains a singleTextContent.- 返回:
trueif this message contains a singleTextContent,falseotherwise.
-
text
已过时。UsesingleText()orcontents()instead.UserMessagecan contain not just a singleString text, but also multipleContents, which can be eitherTextContentorImageContent. Therefore, this method is deprecated. Please usesingleText()if you only expect a single text, or usecontents()otherwise.- 指定者:
text在接口中ChatMessage- 返回:
- the text of the message
-
type
从接口复制的说明:ChatMessageThe type of the message.- 指定者:
type在接口中ChatMessage- 返回:
- the type of the message
-
equals
-
hashCode
public int hashCode() -
toString
-
from
Create aUserMessagefrom a text.- 参数:
text- the text.- 返回:
- the
UserMessage.
-
from
Create aUserMessagefrom a name and a text.- 参数:
name- the name.text- the text.- 返回:
- the
UserMessage.
-
from
Create aUserMessagefrom contents.- 参数:
contents- the contents.- 返回:
- the
UserMessage.
-
from
Create aUserMessagefrom a name and contents.- 参数:
name- the name.contents- the contents.- 返回:
- the
UserMessage.
-
from
Create aUserMessagefrom contents.- 参数:
contents- the contents.- 返回:
- the
UserMessage.
-
from
Create aUserMessagefrom a name and contents.- 参数:
name- the name.contents- the contents.- 返回:
- the
UserMessage.
-
userMessage
Create aUserMessagefrom a text.- 参数:
text- the text.- 返回:
- the
UserMessage.
-
userMessage
Create aUserMessagefrom a name and a text.- 参数:
name- the name.text- the text.- 返回:
- the
UserMessage.
-
userMessage
Create aUserMessagefrom contents.- 参数:
contents- the contents.- 返回:
- the
UserMessage.
-
userMessage
Create aUserMessagefrom a name and contents.- 参数:
name- the name.contents- the contents.- 返回:
- the
UserMessage.
-
userMessage
Create aUserMessagefrom contents.- 参数:
contents- the contents.- 返回:
- the
UserMessage.
-
userMessage
Create aUserMessagefrom a name and contents.- 参数:
name- the name.contents- the contents.- 返回:
- the
UserMessage.
-
singleText()orcontents()instead.