Class MessageContent
-
- All Implemented Interfaces:
public final class MessageContentReferences an image File in the content of a message.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceMessageContent.VisitorAn interface that defines how to map each variant of MessageContent to a value of type T.
-
Method Summary
Modifier and Type Method Description final Optional<ImageFileContentBlock>imageFile()References an image File in the content of a message. final Optional<ImageUrlContentBlock>imageUrl()References an image URL in the content of a message. final Optional<TextContentBlock>text()The text content that is part of a message. final Optional<RefusalContentBlock>refusal()The refusal content generated by the assistant. final BooleanisImageFile()final BooleanisImageUrl()final BooleanisText()final BooleanisRefusal()final ImageFileContentBlockasImageFile()References an image File in the content of a message. final ImageUrlContentBlockasImageUrl()References an image URL in the content of a message. final TextContentBlockasText()The text content that is part of a message. final RefusalContentBlockasRefusal()The refusal content generated by the assistant. final Optional<JsonValue>_json()final <T extends Any> Taccept(MessageContent.Visitor<T> visitor)Maps this instance's current variant to a value of type T using the given visitor. final MessageContentvalidate()Validates that the types of all values in this object match their expected types recursively. final BooleanisValid()Booleanequals(Object other)IntegerhashCode()StringtoString()final static MessageContentofImageFile(ImageFileContentBlock imageFile)References an image File in the content of a message. final static MessageContentofImageUrl(ImageUrlContentBlock imageUrl)References an image URL in the content of a message. final static MessageContentofText(TextContentBlock text)The text content that is part of a message. final static MessageContentofRefusal(RefusalContentBlock refusal)The refusal content generated by the assistant. -
-
Method Detail
-
imageFile
final Optional<ImageFileContentBlock> imageFile()
References an image File in the content of a message.
-
imageUrl
final Optional<ImageUrlContentBlock> imageUrl()
References an image URL in the content of a message.
-
text
final Optional<TextContentBlock> text()
The text content that is part of a message.
-
refusal
final Optional<RefusalContentBlock> refusal()
The refusal content generated by the assistant.
-
isImageFile
final Boolean isImageFile()
-
isImageUrl
final Boolean isImageUrl()
-
asImageFile
final ImageFileContentBlock asImageFile()
References an image File in the content of a message.
-
asImageUrl
final ImageUrlContentBlock asImageUrl()
References an image URL in the content of a message.
-
asText
final TextContentBlock asText()
The text content that is part of a message.
-
asRefusal
final RefusalContentBlock asRefusal()
The refusal content generated by the assistant.
-
accept
final <T extends Any> T accept(MessageContent.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.openai.core.JsonValue; import java.util.Optional; Optional<String> result = messageContent.accept(new MessageContent.Visitor<Optional<String>>() { @Override public Optional<String> visitImageFile(ImageFileContentBlock imageFile) { return Optional.of(imageFile.toString()); } // ... @Override public Optional<String> unknown(JsonValue json) { // Or inspect the `json`. return Optional.empty(); } });
-
validate
final MessageContent 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.
-
ofImageFile
final static MessageContent ofImageFile(ImageFileContentBlock imageFile)
References an image File in the content of a message.
-
ofImageUrl
final static MessageContent ofImageUrl(ImageUrlContentBlock imageUrl)
References an image URL in the content of a message.
-
ofText
final static MessageContent ofText(TextContentBlock text)
The text content that is part of a message.
-
ofRefusal
final static MessageContent ofRefusal(RefusalContentBlock refusal)
The refusal content generated by the assistant.
-
-
-
-