GenerativeModel

public final class GenerativeModel


A controller for communicating with the API of a given multimodal model (for example, Gemini).

Summary

Nested types

public static class GenerativeModel.Companion

Public methods

final @NonNull CountTokensResponse

Counts the amount of tokens in the image prompt.

final @NonNull CountTokensResponse

Counts the amount of tokens in a prompt.

final @NonNull CountTokensResponse

Counts the amount of tokens in the text prompt.

final @NonNull GenerateContentResponse

Generates a GenerateContentResponse from the backend with the provided image prompt.

final @NonNull GenerateContentResponse

Generates a GenerateContentResponse from the backend with the provided Content.

final @NonNull GenerateContentResponse

Generates a GenerateContentResponse from the backend with the provided text prompt.

final @NonNull Flow<@NonNull GenerateContentResponse>

Generates a streaming response from the backend with the provided image prompt.

final @NonNull Flow<@NonNull GenerateContentResponse>

Generates a streaming response from the backend with the provided Content.

final @NonNull Flow<@NonNull GenerateContentResponse>

Generates a streaming response from the backend with the provided text prompt.

final @NonNull Chat

Creates a Chat instance which internally tracks the ongoing conversation with the model

Public fields

generationConfig

public final GenerationConfig generationConfig

modelName

public final @NonNull String modelName

safetySettings

public final List<@NonNull SafetySettingsafetySettings

systemInstruction

public final Content systemInstruction

toolConfig

public final ToolConfig toolConfig

tools

public final List<@NonNull Tooltools

Public methods

countTokens

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

Counts the amount of tokens in the image prompt.

Parameters
@NonNull Bitmap prompt

The image to be converted to a single piece of Content to count the tokens of.

Returns
@NonNull CountTokensResponse

A CountTokensResponse containing the amount of tokens in the prompt.

countTokens

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

Counts the amount of tokens in a prompt.

Parameters
@NonNull Content prompt

A group of Content to count tokens of.

Returns
@NonNull CountTokensResponse

A CountTokensResponse containing the amount of tokens in the prompt.

countTokens

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

Counts the amount of tokens in the text prompt.

Parameters
@NonNull String prompt

The text to be converted to a single piece of Content to count the tokens of.

Returns
@NonNull CountTokensResponse

A CountTokensResponse containing the amount of tokens in the prompt.

generateContent

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

Generates a GenerateContentResponse from the backend with the provided image prompt.

Parameters
@NonNull Bitmap prompt

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

Returns
@NonNull GenerateContentResponse

A GenerateContentResponse after some delay. Function should be called within a suspend context to properly manage concurrency.

generateContent

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

Generates a GenerateContentResponse from the backend with the provided Content.

Parameters
@NonNull Content prompt

Content to send to the model.

Returns
@NonNull GenerateContentResponse

A GenerateContentResponse. Function should be called within a suspend context to properly manage concurrency.

generateContent

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

Generates a GenerateContentResponse from the backend with the provided text prompt.

Parameters
@NonNull String prompt

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

Returns
@NonNull GenerateContentResponse

A GenerateContentResponse after some delay. Function should be called within a suspend context to properly manage concurrency.

generateContentStream

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

Generates a streaming response from the backend with the provided image 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 from the model.

generateContentStream

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

Generates a streaming response from the backend with the provided Content.

Parameters
@NonNull Content prompt

Content to send to the model.

Returns
@NonNull Flow<@NonNull GenerateContentResponse>

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

generateContentStream

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

Generates a streaming response from the backend with the provided text prompt.

Parameters
@NonNull String prompt

The text 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 from the model.

startChat

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

Creates a Chat instance which internally tracks the ongoing conversation with the model