Content.Builder

class Content.Builder


Builder class to facilitate constructing complex Content objects.

Summary

Public constructors

Public functions

Content

Returns a new Content using the defined role and parts.

Content.Builder
fileData(uri: String, mimeType: String)

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

Content.Builder
image(image: Bitmap)

Adds a new ImagePart with the provided image to parts.

Content.Builder
inlineData(bytes: ByteArray, mimeType: String)

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

Content.Builder
<T : Part> part(data: T)

Adds a new Part to parts.

Content.Builder
text(text: String)

Adds a new TextPart with the provided text to parts.

Public properties

MutableList<Part>

The mutable list of Parts comprising the Content.

String?

The producer of the content.

Public constructors

Builder

Builder()

Public functions

build

fun build(): Content

Returns a new Content using the defined role and parts.

fileData

fun fileData(uri: String, mimeType: String): Content.Builder

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

image

fun image(image: Bitmap): Content.Builder

Adds a new ImagePart with the provided image to parts.

inlineData

fun inlineData(bytes: ByteArray, mimeType: String): Content.Builder

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

part

fun <T : Part> part(data: T): Content.Builder

Adds a new Part to parts.

text

fun text(text: String): Content.Builder

Adds a new TextPart with the provided text to parts.

Public properties

parts

var partsMutableList<Part>

The mutable list of Parts comprising the Content.

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

role

var roleString?

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