GenerativeModel

public final class GenerativeModel


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

Summary

Public methods

final @NonNull CountTokensResponse

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

final @NonNull CountTokensResponse

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

final @NonNull CountTokensResponse

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

final @NonNull GenerateContentResponse

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

final @NonNull GenerateContentResponse

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

final @NonNull GenerateContentResponse

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

final @NonNull Flow<@NonNull GenerateContentResponse>

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

final @NonNull Flow<@NonNull GenerateContentResponse>

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

final @NonNull Flow<@NonNull GenerateContentResponse>

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

final @NonNull Chat

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

Public methods

countTokens

public final @NonNull CountTokensResponse countTokens(@NonNull Bitmap prompt)

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

Parameters
@NonNull Bitmap prompt

The image given to the model as a prompt.

Returns
@NonNull 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

public final @NonNull CountTokensResponse countTokens(@NonNull Content prompt)

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

Parameters
@NonNull Content prompt

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

Returns
@NonNull 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

public final @NonNull CountTokensResponse countTokens(@NonNull String prompt)

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

Parameters
@NonNull String prompt

The text given to the model as a prompt.

Returns
@NonNull 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

public final @NonNull GenerateContentResponse generateContent(@NonNull Bitmap prompt)

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

Parameters
@NonNull Bitmap 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 @NonNull GenerateContentResponse generateContent(@NonNull Content prompt)

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

Parameters
@NonNull Content prompt

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

Returns
@NonNull 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

public final @NonNull GenerateContentResponse generateContent(@NonNull String prompt)

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

Parameters
@NonNull String prompt

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

Returns
@NonNull 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

public final @NonNull Flow<@NonNull GenerateContentResponsegenerateContentStream(@NonNull Bitmap prompt)

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

Parameters
@NonNull Bitmap prompt

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

Returns
@NonNull Flow<@NonNull 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

public final @NonNull Flow<@NonNull GenerateContentResponsegenerateContentStream(@NonNull Content prompt)

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

Parameters
@NonNull Content prompt

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

Returns
@NonNull Flow<@NonNull 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

public final @NonNull Flow<@NonNull GenerateContentResponsegenerateContentStream(@NonNull String prompt)

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

Parameters
@NonNull String prompt

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

Returns
@NonNull Flow<@NonNull 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

public final @NonNull Chat startChat(@NonNull List<@NonNull Content> history)

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