GenerativeModel

class GenerativeModel

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

Summary

Public functions

suspend CountTokensResponse

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

suspend CountTokensResponse
countTokens(vararg prompt: Content)

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

suspend CountTokensResponse

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

suspend GenerateContentResponse

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

suspend GenerateContentResponse
generateContent(vararg prompt: Content)

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

suspend GenerateContentResponse

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

Flow<GenerateContentResponse>

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

Flow<GenerateContentResponse>
generateContentStream(vararg prompt: Content)

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

Flow<GenerateContentResponse>

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

Chat
startChat(history: List<Content>)

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

Public functions

countTokens

suspend fun countTokens(prompt: Bitmap): CountTokensResponse

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

Parameters
prompt: Bitmap

The image given to the model as a prompt.

Returns
CountTokensResponse

The CountTokensResponse of running the model's tokenizer on the input.

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException: com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

countTokens

suspend fun countTokens(vararg prompt: Content): CountTokensResponse

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

Parameters
vararg prompt: Content

The input(s) given to the model as a prompt.

Returns
CountTokensResponse

The CountTokensResponse of running the model's tokenizer on the input.

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException: com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

countTokens

suspend fun countTokens(prompt: String): CountTokensResponse

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

Parameters
prompt: String

The text given to the model as a prompt.

Returns
CountTokensResponse

The CountTokensResponse of running the model's tokenizer on the input.

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException: com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

generateContent

suspend fun generateContent(prompt: Bitmap): GenerateContentResponse

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

Parameters
prompt: Bitmap

The image to be converted into a single piece of Content to send to the model.

Returns
GenerateContentResponse

A GenerateContentResponse after some delay.

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException: com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

generateContent

suspend fun generateContent(vararg prompt: Content): GenerateContentResponse

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

Parameters
vararg prompt: Content

The input(s) given to the model as a prompt.

Returns
GenerateContentResponse

The content generated by the model.

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException: com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

generateContent

suspend fun generateContent(prompt: String): GenerateContentResponse

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

Parameters
prompt: String

The text to be send to the model as a prompt.

Returns
GenerateContentResponse

The content generated by the model.

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException: com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

generateContentStream

fun generateContentStream(prompt: Bitmap): Flow<GenerateContentResponse>

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

Parameters
prompt: Bitmap

The image to be converted into a single piece of Content to send to the model.

Returns
Flow<GenerateContentResponse>

A Flow which will emit responses as they are returned by the model.

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException: com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

generateContentStream

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

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

Parameters
vararg prompt: Content

The input(s) given to the model as a prompt.

Returns
Flow<GenerateContentResponse>

A Flow which will emit responses as they are returned by the model.

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException: com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

generateContentStream

fun generateContentStream(prompt: String): Flow<GenerateContentResponse>

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

Parameters
prompt: String

The text to be send to the model as a prompt.

Returns
Flow<GenerateContentResponse>

A Flow which will emit responses as they are returned by the model.

Throws
com.google.firebase.vertexai.type.FirebaseVertexAIException: com.google.firebase.vertexai.type.FirebaseVertexAIException

if the request failed.

See also
FirebaseVertexAIException

for types of errors.

startChat

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

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