com.google.mlkit.genai.prompt
Interfaces
Caches
|
Provides an interface to explicitly manage caches for |
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 |
GenerateContentRequest
|
A request to generate content. |
GenerateContentRequest.Builder
|
Builder for |
GenerateContentResponse
|
Represents a response from the model. |
GenerationConfig
|
Configuration parameters to use for content generation. |
GenerationConfig.Builder
|
Builder for |
ImagePart
|
A data class representing an image part of a prompt. |
ModelConfig
|
Specifies the desired model for content generation. |
ModelConfig.Builder
|
Builder for |
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
Entry class to get a GenerativeModel
client.
Annotations
Candidate.FinishReason
|
The reason why this |
ModelPreference
|
Defines the developer's preference to guide model selection, balancing characteristics like speed and capability. |
ModelReleaseStage
|
Defines the release stage preference for model selection. |
Top-level functions summary
CreateCachedContextRequest
|
createCachedContextRequest
(name: String
, promptPrefix: PromptPrefix
)
Helper method to construct a |
GenerateContentRequest
|
generateContentRequest
(text: TextPart
, init: GenerateContentRequest.Builder
.() ->
Unit
)
Helper method to construct a |
GenerateContentRequest
|
generateContentRequest
(image: ImagePart
, text: TextPart
, init: GenerateContentRequest.Builder
.() ->
Unit
)
Helper method to construct a |
GenerationConfig
|
generationConfig
(init: GenerationConfig.Builder
.() ->
Unit
)
Helper method to construct a |
ModelConfig
|
modelConfig
(init: ModelConfig.Builder
.() ->
Unit
)
Helper function for Kotlin DSL to build ModelConfig. |
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:
// Default generation config - uses ModelConfig.DEFAULT and a default background thread pool.
val config1 = generationConfig {}
// Customized model spec
val config2 = generationConfig {
workerExecutor = myExecutor
modelConfig = modelConfig {
releaseStage = ModelReleaseStage.PREVIEW
preference = ModelPreference.FAST
}
}
// Using prebuilt default ModelConfig with a custom executor
val config3 = generationConfig {
workerExecutor = myExecutor
modelConfig = ModelConfig.DEFAULT
}
modelConfig
fun modelConfig (init: ModelConfig.Builder .() -> Unit ): ModelConfig
Helper function for Kotlin DSL to build ModelConfig.


