Content.Builder

class Content.Builder


Builder class to facilitate constructing complex Content objects.

Summary

Public constructors

Public functions

Content.Builder
blob(mimeType: String, blob: ByteArray)

Wraps the provided blob and mimeType inside a BlobPart and adds it to the parts list.

Content

Returns a new Content using the defined role and parts.

Content.Builder
image(image: Bitmap)

Wraps the provided image inside an ImagePart and adds it to the parts list.

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

Adds a new Part to parts.

Content.Builder
text(text: String)

Wraps the provided text inside a TextPart and adds it to parts list.

Public properties

MutableList<Part>

Mutable list of Part comprising a single Content.

String?

The producer of the content.

Public constructors

Builder

Builder()

Public functions

blob

fun blob(mimeType: String, blob: ByteArray): Content.Builder

Wraps the provided blob and mimeType inside a BlobPart and adds it to the parts list.

build

fun build(): Content

Returns a new Content using the defined role and parts.

image

fun image(image: Bitmap): Content.Builder

Wraps the provided image inside an ImagePart and adds it to the parts list.

part

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

Adds a new Part to parts.

text

fun text(text: String): Content.Builder

Wraps the provided text inside a TextPart and adds it to parts list.

Public properties

parts

var partsMutableList<Part>

Mutable list of Part comprising a single Content.

Prefer using the provided helper methods over adding elements to the list directly.

role

var roleString?

The producer of the content. By default, it's "user".