GenerativeModel

actual class GenerativeModel(source)

Represents a multimodal model (like Gemini), capable of generating content based on various input types.

On Android the model also takes an android.graphics.Bitmap prompt in generateContent, generateContentStream and countTokens; send images as InlineDataParts in common code.

expect class GenerativeModel(source)

Represents a multimodal model (like Gemini), capable of generating content based on various input types.

On Android the model also takes an android.graphics.Bitmap prompt in generateContent, generateContentStream and countTokens; send images as InlineDataParts in common code.

actual class GenerativeModel(source)

A model of the cloud backend, over the platform SDK. The platforms other than Android have no on-device model (as Android without the firebase-ai-ondevice library): OnDeviceConfig modes that prefer one of the two fall back to the cloud, ONLY_ON_DEVICE fails with FirebaseAIOnDeviceNotAvailableException, and onDeviceExtension is null.

Properties

Link copied to clipboard

The extension for on-device inference, when the model was created with an OnDeviceConfig.

The extension for on-device inference, when the model was created with an OnDeviceConfig.

The extension for on-device inference, when the model was created with an OnDeviceConfig.

Functions

Link copied to clipboard
actual suspend fun countTokens(prompt: String): CountTokensResponse

Counts the number of tokens in a text prompt using the model's tokenizer.

actual suspend fun countTokens(prompt: List<Content>): CountTokensResponse
actual suspend fun countTokens(prompt: Content, vararg prompts: Content): CountTokensResponse

Counts the number of tokens in a prompt using the model's tokenizer.

expect suspend fun countTokens(prompt: String): CountTokensResponse

Counts the number of tokens in a text prompt using the model's tokenizer.

expect suspend fun countTokens(prompt: List<Content>): CountTokensResponse
expect suspend fun countTokens(prompt: Content, vararg prompts: Content): CountTokensResponse

Counts the number of tokens in a prompt using the model's tokenizer.

actual suspend fun countTokens(prompt: String): CountTokensResponse

Counts the number of tokens in a text prompt using the model's tokenizer.

actual suspend fun countTokens(prompt: List<Content>): CountTokensResponse
actual suspend fun countTokens(prompt: Content, vararg prompts: Content): CountTokensResponse

Counts the number of tokens in a prompt using the model's tokenizer.

Link copied to clipboard
actual suspend fun generateContent(prompt: String): GenerateContentResponse

Generates new content from the text input given to the model as a prompt.

actual suspend fun generateContent(prompt: List<Content>): GenerateContentResponse
actual suspend fun generateContent(prompt: Content, vararg prompts: Content): GenerateContentResponse

Generates new content from the input Content given to the model as a prompt.

expect suspend fun generateContent(prompt: String): GenerateContentResponse

Generates new content from the text input given to the model as a prompt.

expect suspend fun generateContent(prompt: List<Content>): GenerateContentResponse
expect suspend fun generateContent(prompt: Content, vararg prompts: Content): GenerateContentResponse

Generates new content from the input Content given to the model as a prompt.

actual suspend fun generateContent(prompt: String): GenerateContentResponse

Generates new content from the text input given to the model as a prompt.

actual suspend fun generateContent(prompt: List<Content>): GenerateContentResponse
actual suspend fun generateContent(prompt: Content, vararg prompts: Content): GenerateContentResponse

Generates new content from the input Content given to the model as a prompt.

Link copied to clipboard

Generates new content as a stream from the text input given to the model as a prompt.

actual fun generateContentStream(prompt: Content, vararg prompts: Content): Flow<GenerateContentResponse>

Generates new content as a stream from the input Content given to the model as a prompt.

Generates new content as a stream from the text input given to the model as a prompt.

expect fun generateContentStream(prompt: Content, vararg prompts: Content): Flow<GenerateContentResponse>

Generates new content as a stream from the input Content given to the model as a prompt.

Generates new content as a stream from the text input given to the model as a prompt.

actual fun generateContentStream(prompt: Content, vararg prompts: Content): Flow<GenerateContentResponse>

Generates new content as a stream from the input Content given to the model as a prompt.

Link copied to clipboard
actual suspend fun <T : Any> generateObject(jsonSchema: JsonSchema<T>, prompt: String): GenerateObjectResponse<T>

Generates an object from the text input given to the model as a prompt.

actual suspend fun <T : Any> generateObject(jsonSchema: JsonSchema<T>, prompt: Content, vararg prompts: Content): GenerateObjectResponse<T>

Generates an object from the input Content given to the model as a prompt.

expect suspend fun <T : Any> generateObject(jsonSchema: JsonSchema<T>, prompt: String): GenerateObjectResponse<T>

Generates an object from the text input given to the model as a prompt.

expect suspend fun <T : Any> generateObject(jsonSchema: JsonSchema<T>, prompt: Content, vararg prompts: Content): GenerateObjectResponse<T>

Generates an object from the input Content given to the model as a prompt.

actual suspend fun <T : Any> generateObject(jsonSchema: JsonSchema<T>, prompt: String): GenerateObjectResponse<T>

Generates an object from the text input given to the model as a prompt.

actual suspend fun <T : Any> generateObject(jsonSchema: JsonSchema<T>, prompt: Content, vararg prompts: Content): GenerateObjectResponse<T>

Generates an object from the input Content given to the model as a prompt.

Link copied to clipboard
actual fun startChat(history: List<Content>): Chat

Creates a Chat instance using this model with the optionally provided history.

expect fun startChat(history: List<Content> = emptyList()): Chat

Creates a Chat instance using this model with the optionally provided history.

actual fun startChat(history: List<Content>): Chat

Creates a Chat instance using this model with the optionally provided history.