com.google.mlkit.genai.prompt

Interfaces

Caches

Provides an interface to explicitly manage caches for GenerativeModel.

GenerativeModel

Provides an interface for performing content generation.

Classes

CachedContext

Represents an identifier of a cached context that can be used in inference.

Candidate

A piece of a response from the model.

CountTokensResponse

Data class holding token count information.

CreateCachedContextRequest

A request to create a cached context.

CreateCachedContextRequest.Builder

Builder for CreateCachedContextRequest.

GenerateContentRequest

A request to generate content.

GenerateContentRequest.Builder

Builder for GenerateContentRequest.

GenerateContentResponse

Represents a response from the model.

GenerationConfig

Configuration parameters to use for content generation.

GenerationConfig.Builder

Builder for GenerationConfig.

ImagePart

A data class representing an image part of a prompt.

Part

A sealed class representing a part of a multimodal prompt.

PromptPrefix

A data class representing a prompt prefix.

TextPart

A data class representing a text part of a prompt.

Objects

Generation

Entry class to get a GenerativeModel client.

Annotations

Candidate.FinishReason

The reason why this Candidate is returned.

Top-level functions summary

CreateCachedContextRequest

Helper method to construct a CreateCachedContextRequest.

GenerateContentRequest

Helper method to construct a GenerateContentRequest in a DSL-like manner.

GenerateContentRequest

Helper method to construct a GenerateContentRequest in a DSL-like manner.

GenerationConfig

Helper method to construct a GenerationConfig in a DSL-like manner.

Top-level functions

createCachedContextRequest

fun createCachedContextRequest(name: String, promptPrefix: PromptPrefix): CreateCachedContextRequest

Helper method to construct a CreateCachedContextRequest.

Example Usage:

createCachedContextRequest("my_cache", PromptPrefix("Repeat 3 times: "))

generateContentRequest

fun generateContentRequest(text: TextPart, init: GenerateContentRequest.Builder.() -> Unit): GenerateContentRequest

Helper method to construct a GenerateContentRequest in a DSL-like manner.

Example Usage:

// Generation Request with text only:
generateContentRequest(TextPart("Hello World")) {
temperature = 0.5f
seed = 123
topK = 10
candidateCount = 5
maxOutputTokens = 200
}

generateContentRequest

fun generateContentRequest(image: ImagePart, text: TextPart, init: GenerateContentRequest.Builder.() -> Unit): GenerateContentRequest

Helper method to construct a GenerateContentRequest in a DSL-like manner.

Example Usage:

// Generation Request with image and text:
generateContentRequest(ImagePart(bitmap), TextPart("Hello World")) {
temperature = 0.5f
seed = 123
topK = 10
candidateCount = 5
maxOutputTokens = 200
}

generationConfig

fun generationConfig(init: GenerationConfig.Builder.() -> Unit): GenerationConfig

Helper method to construct a GenerationConfig in a DSL-like manner.

Example usage:

generationConfig() {
workerExecutor = workerThread // Set the [ExecutorService] on which background tasks should be run. If no value is specified, a background thread pool will be used.
}