ContentPartsBuilder

A builder for constructing parts for prompt messages. All parts are added to a list in declaration order and can be retrieved through the build method.

Example usage:

val parts = ContentPartsBuilder().apply {
text("Hello!")
image("screenshot.png")
binaryFile("report.pdf")
}.build()

See also

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

Represents the current caret position in the text being built.

Functions

Link copied to clipboard

Configures media attachments for this content builder.

Link copied to clipboard

Adds ContentPart.Audio to the list of parts.

fun audio(url: String)

Adds ContentPart.Audio with AttachmentContent.URL content from the provided URL.

fun audio(path: Path)

Adds ContentPart.Audio with AttachmentContent.Binary.Bytes content from the provided local file path.

Link copied to clipboard
fun binaryFile(path: Path, mimeType: String)

Adds ContentPart.File with AttachmentContent.Binary.Bytes content from the provided local file path.

Link copied to clipboard
fun br()

Adds two consecutive newline characters to the text content.

Link copied to clipboard
open override fun build(): List<ContentPart>

Constructs and returns the accumulated list of attachment items.

Link copied to clipboard

Adds ContentPart.File to the list of parts.

fun file(url: String, mimeType: String)

Adds ContentPart.File with AttachmentContent.URL content from the provided URL.

Link copied to clipboard

Adds ContentPart.Image to the list of parts.

fun image(url: String)

Adds ContentPart.Image with AttachmentContent.URL content from the provided URL.

fun image(path: Path)

Adds ContentPart.Image with AttachmentContent.Binary.Bytes content from the provided local file path.

Link copied to clipboard
fun newline()

Appends a newline character to the underlying text builder.

Link copied to clipboard
open operator fun String.not()

Defines a custom operator function for the String class. This unary not operator (!) is invoked on a String instance and performs a custom action defined by the text function.

Link copied to clipboard
fun TextContentBuilderBase<*>.numbered(startLineNumber: Int = 1, body: TextContentBuilderBase<*>.() -> Unit): TextContentBuilderBase<*>

Extension function for TextContentBuilder that adds line numbering to the content.

Link copied to clipboard
fun padding(padding: String, body: TextContentBuilder.() -> Unit)

Adds padding to each line of the content produced by the provided builder block.

Link copied to clipboard
fun part(contentPart: ContentPart)

Adds ContentPart to the list of parts.

Link copied to clipboard

Adds ContentPart.Text to the list of parts.

open fun text(text: String)

Appends the given text to the current content.

Link copied to clipboard

Extension function to add text content to a TextContentBuilder.

Link copied to clipboard
fun textFile(path: Path, mimeType: String)

Adds ContentPart.File with AttachmentContent.PlainText content from the provided local file path.

Link copied to clipboard

Adds the given text to the content. If the caret is not at the beginning of the line, a newline is added before appending the text.

Link copied to clipboard
open operator fun String.unaryPlus()

Adds the given string as a new line of text to the content being built by the TextContentBuilder.

Link copied to clipboard

Adds ContentPart.Video to the list of parts.

fun video(url: String)

Adds ContentPart.Video with AttachmentContent.URL content from the provided URL.

fun video(path: Path)

Adds ContentPart.Video with AttachmentContent.Binary.Bytes content from the provided local file path.