Class MessageParam
-
- All Implemented Interfaces:
public final class MessageParam
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceMessageParam.VisitorAn interface that defines how to map each variant of MessageParam to a value of type T.
public final classMessageParam.Role
-
Method Summary
Modifier and Type Method Description final Optional<UserMessageParam>user()final Optional<AssistantMessageParam>assistant()final Optional<SystemMessageParam>system()final Optional<JsonValue>_json()final MessageParam.Rolerole()final MessageContentParamcontent()final BooleanisUser()final BooleanisAssistant()final BooleanisSystem()final UserMessageParamasUser()final AssistantMessageParamasAssistant()final SystemMessageParamasSystem()final <T extends Any> Taccept(MessageParam.Visitor<T> visitor)Maps this instance's current variant to a value of type T using the given visitor. final MessageParamvalidate()Validates that the types of all values in this object match their expected types recursively. final BooleanisValid()Booleanequals(Object other)IntegerhashCode()StringtoString()final static MessageParamofUser(UserMessageParam user)final static MessageParamofUser(MessageContentParam content)Returns an immutable instance of MessageParam whose ofUser variant is built from the given required content. final static MessageParamofUser(String string)Alias for calling ofUser with MessageContentParam.ofString(string).final static MessageParamofUserOfContentBlockParams(List<ContentBlockParam> contentBlockParams)Alias for calling ofUser with MessageContentParam.ofContentBlockParams(contentBlockParams).final static MessageParamofAssistant(AssistantMessageParam assistant)final static MessageParamofAssistant(MessageContentParam content)Returns an immutable instance of MessageParam whose ofAssistant variant is built from the given required content. final static MessageParamofAssistant(String string)Alias for calling ofAssistant with MessageContentParam.ofString(string).final static MessageParamofAssistantOfContentBlockParams(List<ContentBlockParam> contentBlockParams)Alias for calling ofAssistant with MessageContentParam.ofContentBlockParams(contentBlockParams).final static MessageParamofSystem(SystemMessageParam system)final static MessageParamofSystem(SystemMessageParam.Content content)Returns an immutable instance of MessageParam whose ofSystem variant is built from the given required content. final static MessageParamofSystem(String string)Alias for calling ofSystem with SystemMessageParam.Content.ofString(string).final static MessageParamofSystemOfBlocks(List<TextBlockParam> blocks)Alias for calling ofSystem with SystemMessageParam.Content.ofBlocks(blocks).-
-
Method Detail
-
user
final Optional<UserMessageParam> user()
-
assistant
final Optional<AssistantMessageParam> assistant()
-
system
final Optional<SystemMessageParam> system()
-
role
final MessageParam.Role role()
-
content
final MessageContentParam content()
-
isAssistant
final Boolean isAssistant()
-
asUser
final UserMessageParam asUser()
-
asAssistant
final AssistantMessageParam asAssistant()
-
asSystem
final SystemMessageParam asSystem()
-
accept
final <T extends Any> T accept(MessageParam.Visitor<T> visitor)
Maps this instance's current variant to a value of type T using the given visitor.
Note that this method is not forwards compatible with new variants from the API, unless visitor overrides Visitor.unknown. To handle variants not known to this version of the SDK gracefully, consider overriding Visitor.unknown:
import com.anthropic.core.JsonValue; import java.util.Optional; Optional<String> result = messageParam.accept(new MessageParam.Visitor<Optional<String>>() { @Override public Optional<String> visitUser(UserMessageParam user) { return Optional.of(user.toString()); } // ... @Override public Optional<String> unknown(JsonValue json) { // Or inspect the `json`. return Optional.empty(); } });
-
validate
final MessageParam validate()
Validates that the types of all values in this object match their expected types recursively.
This method is not forwards compatible with new types from the API for existing fields.
-
ofUser
final static MessageParam ofUser(UserMessageParam user)
-
ofUser
final static MessageParam ofUser(MessageContentParam content)
Returns an immutable instance of MessageParam whose ofUser variant is built from the given required content.
-
ofUser
final static MessageParam ofUser(String string)
Alias for calling ofUser with
MessageContentParam.ofString(string).
-
ofUserOfContentBlockParams
final static MessageParam ofUserOfContentBlockParams(List<ContentBlockParam> contentBlockParams)
Alias for calling ofUser with
MessageContentParam.ofContentBlockParams(contentBlockParams).
-
ofAssistant
final static MessageParam ofAssistant(AssistantMessageParam assistant)
-
ofAssistant
final static MessageParam ofAssistant(MessageContentParam content)
Returns an immutable instance of MessageParam whose ofAssistant variant is built from the given required content.
-
ofAssistant
final static MessageParam ofAssistant(String string)
Alias for calling ofAssistant with
MessageContentParam.ofString(string).
-
ofAssistantOfContentBlockParams
final static MessageParam ofAssistantOfContentBlockParams(List<ContentBlockParam> contentBlockParams)
Alias for calling ofAssistant with
MessageContentParam.ofContentBlockParams(contentBlockParams).
-
ofSystem
final static MessageParam ofSystem(SystemMessageParam system)
-
ofSystem
final static MessageParam ofSystem(SystemMessageParam.Content content)
Returns an immutable instance of MessageParam whose ofSystem variant is built from the given required content.
-
ofSystem
final static MessageParam ofSystem(String string)
Alias for calling ofSystem with
SystemMessageParam.Content.ofString(string).
-
ofSystemOfBlocks
final static MessageParam ofSystemOfBlocks(List<TextBlockParam> blocks)
Alias for calling ofSystem with
SystemMessageParam.Content.ofBlocks(blocks).
-
-
-
-