Class Content

  • All Implemented Interfaces:

    
    public abstract class Content
    extends JsonSerializable
                        

    Contains the multi-part content of a message.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public abstract class Content.Builder

      Builder for Content.

    • Constructor Summary

      Constructors 
      Constructor Description
      Content()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract Optional<List<Part>> parts() List of parts that constitute a single message.
      abstract Optional<String> role() Optional.
      static Content.Builder builder() Instantiates a builder for Content.
      abstract Content.Builder toBuilder() Creates a builder with the same values as this instance.
      static Content fromJson(String jsonString) Deserializes a JSON string to a Content object.
      static Content fromParts(Array<Part> parts) Constructs a Content from parts, assuming the role is "user".
      String text() Returns the concatenation of all text parts in this content.
      • Methods inherited from class com.google.genai.JsonSerializable

        fromJsonNode, fromJsonString, objectMapper, setMaxReadLength, stringToJsonNode, toJson, toJsonNode, toJsonString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Content

        Content()
    • Method Detail

      • parts

         abstract Optional<List<Part>> parts()

        List of parts that constitute a single message. Each part may have a different IANA MIME type.

      • role

         abstract Optional<String> role()

        Optional. The producer of the content. Must be either 'user' or 'model'. If not set, the service will default to 'user'.

      • text

        @Nullable() String text()

        Returns the concatenation of all text parts in this content.

        Returns null if there are no parts in the content. Returns an empty string if parts exists but none of the parts contain text.