Content.Builder

public final class Content.Builder


Builder class to facilitate constructing complex Content objects.

Summary

Public fields

final @NonNull List<@NonNull Part>

The mutable list of Parts comprising the Content.

final String

The producer of the content.

Public constructors

Public methods

final @NonNull Content.Builder

Adds a new FileDataPart with the provided uri and mimeType to parts.

final @NonNull Content.Builder

Adds a new ImagePart with the provided image to parts.

final @NonNull Content.Builder
addInlineData(@NonNull byte[] bytes, @NonNull String mimeType)

Adds a new InlineDataPart with the provided bytes, which should be interpreted by the model based on the mimeType, to parts.

final @NonNull Content.Builder
<T extends Part> addPart(@NonNull T data)

Adds a new Part to parts.

final @NonNull Content.Builder

Adds a new TextPart with the provided text to parts.

final @NonNull Content

Returns a new Content using the defined role and parts.

Public fields

parts

public final @NonNull List<@NonNull Partparts

The mutable list of Parts comprising the Content.

Prefer using the provided helper methods over modifying this list directly.

role

public final String role

The producer of the content. Must be either 'user' or 'model'. By default, it's "user".

Public constructors

Builder

public Builder()

Public methods

addFileData

public final @NonNull Content.Builder addFileData(@NonNull String uri, @NonNull String mimeType)

Adds a new FileDataPart with the provided uri and mimeType to parts.

addImage

public final @NonNull Content.Builder addImage(@NonNull Bitmap image)

Adds a new ImagePart with the provided image to parts.

addInlineData

public final @NonNull Content.Builder addInlineData(@NonNull byte[] bytes, @NonNull String mimeType)

Adds a new InlineDataPart with the provided bytes, which should be interpreted by the model based on the mimeType, to parts.

addPart

public final @NonNull Content.Builder <T extends Part> addPart(@NonNull T data)

Adds a new Part to parts.

addText

public final @NonNull Content.Builder addText(@NonNull String text)

Adds a new TextPart with the provided text to parts.

build

public final @NonNull Content build()

Returns a new Content using the defined role and parts.