GenerativeModel

public final class GenerativeModel


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

Summary

Public methods

final @NonNullCountTokensResponse

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

final @NonNullCountTokensResponse

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

final @NonNullCountTokensResponse

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

final @NonNullGenerateContentResponse

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

final @NonNullGenerateContentResponse

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

final @NonNullGenerateContentResponse

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

final @NonNullFlow<@NonNullGenerateContentResponse>

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

final @NonNullFlow<@NonNullGenerateContentResponse>

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

final @NonNullFlow<@NonNullGenerateContentResponse>

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

final @NonNullChat

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

Public methods

countTokens

public final @NonNullCountTokensResponse countTokens(@NonNullBitmap prompt)

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

Parameters
@NonNullBitmap prompt

The image given to the model as a prompt.

Returns
@NonNullCountTokensResponse

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

public final @NonNullCountTokensResponse countTokens(@NonNullContent prompt)

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

Parameters
@NonNullContent prompt

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

Returns
@NonNullCountTokensResponse

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

public final @NonNullCountTokensResponse countTokens(@NonNullString prompt)

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

Parameters
@NonNullString prompt

The text given to the model as a prompt.

Returns
@NonNullCountTokensResponse

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

public final @NonNullGenerateContentResponse generateContent(@NonNullBitmap prompt)

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

Parameters
@NonNullBitmap prompt

The image to be converted into a single piece of Content to send to 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

public final @NonNullGenerateContentResponse generateContent(@NonNullContent prompt)

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

Parameters
@NonNullContent prompt

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

Returns
@NonNullGenerateContentResponse

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

public final @NonNullGenerateContentResponse generateContent(@NonNullString prompt)

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

Parameters
@NonNullString prompt

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

Returns
@NonNullGenerateContentResponse

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

public final @NonNullFlow<@NonNullGenerateContentResponsegenerateContentStream(@NonNullBitmap prompt)

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

Parameters
@NonNullBitmap prompt

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

Returns
@NonNullFlow<@NonNullGenerateContentResponse>

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

public final @NonNullFlow<@NonNullGenerateContentResponsegenerateContentStream(@NonNullContent prompt)

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

Parameters
@NonNullContent prompt

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

Returns
@NonNullFlow<@NonNullGenerateContentResponse>

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

public final @NonNullFlow<@NonNullGenerateContentResponsegenerateContentStream(@NonNullString prompt)

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

Parameters
@NonNullString prompt

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

Returns
@NonNullFlow<@NonNullGenerateContentResponse>

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

public final @NonNullChat startChat(@NonNullList<@NonNullContent> history)

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