FirebaseAI

class FirebaseAI


Entry point for all Firebase AI functionality.

Summary

Public companion functions

FirebaseAI

The FirebaseAI instance for the provided FirebaseApp using the Google AI Backend.

FirebaseAI

Returns the FirebaseAI instance for the provided FirebaseApp and backend.

FirebaseAI
getInstance(
    app: FirebaseApp,
    backend: GenerativeBackend,
    useLimitedUseAppCheckTokens: Boolean
)

Returns the FirebaseAI instance for the provided FirebaseApp and backend.

Public companion properties

FirebaseAI

The FirebaseAI instance for the default FirebaseApp using the Google AI Backend.

Public functions

GenerativeModel
generativeModel(
    modelName: String,
    generationConfig: GenerationConfig?,
    safetySettings: List<SafetySetting>?,
    tools: List<Tool>?,
    toolConfig: ToolConfig?,
    systemInstruction: Content?,
    requestOptions: RequestOptions
)

Instantiates a new GenerativeModel given the provided parameters.

ImagenModel
@PublicPreviewAPI
imagenModel(
    modelName: String,
    generationConfig: ImagenGenerationConfig?,
    safetySettings: ImagenSafetySettings?,
    requestOptions: RequestOptions
)

Instantiates a new ImagenModel given the provided parameters.

LiveGenerativeModel
@PublicPreviewAPI
liveModel(
    modelName: String,
    generationConfig: LiveGenerationConfig?,
    tools: List<Tool>?,
    systemInstruction: Content?,
    requestOptions: RequestOptions
)

Instantiates a new LiveGenerationConfig given the provided parameters.

Public companion functions

getInstance

fun getInstance(app: FirebaseApp): FirebaseAI

The FirebaseAI instance for the provided FirebaseApp using the Google AI Backend.

getInstance

fun getInstance(app: FirebaseApp = Firebase.app, backend: GenerativeBackend): FirebaseAI

Returns the FirebaseAI instance for the provided FirebaseApp and backend.

Parameters
backend: GenerativeBackend

the backend reference to make generative AI requests to.

getInstance

fun getInstance(
    app: FirebaseApp = Firebase.app,
    backend: GenerativeBackend,
    useLimitedUseAppCheckTokens: Boolean
): FirebaseAI

Returns the FirebaseAI instance for the provided FirebaseApp and backend.

Parameters
backend: GenerativeBackend

the backend reference to make generative AI requests to.

useLimitedUseAppCheckTokens: Boolean

when sending tokens to the backend, this option enables the usage of App Check's limited-use tokens instead of the standard cached tokens.

A new limited-use tokens will be generated for each request; providing a smaller attack surface for malicious parties to hijack tokens. When used alongside replay protection, limited-use tokens are also consumed after each request, ensuring they can't be used again.

This flag is set to false by default.

Important: Replay protection is not currently supported for the FirebaseAI backend. While this feature is being developed, you can still migrate to using limited-use tokens. Because limited-use tokens are backwards compatible, you can still use them without replay protection. Due to their shorter TTL over standard App Check tokens, they still provide a security benefit. Migrating to limited-use tokens sooner minimizes disruption when support for replay protection is added.

Public companion properties

instance

val instanceFirebaseAI

The FirebaseAI instance for the default FirebaseApp using the Google AI Backend.

Public functions

generativeModel

fun generativeModel(
    modelName: String,
    generationConfig: GenerationConfig? = null,
    safetySettings: List<SafetySetting>? = null,
    tools: List<Tool>? = null,
    toolConfig: ToolConfig? = null,
    systemInstruction: Content? = null,
    requestOptions: RequestOptions = RequestOptions()
): GenerativeModel

Instantiates a new GenerativeModel given the provided parameters.

Parameters
modelName: String

The name of the model to use. See the documentation for a list of supported models.

generationConfig: GenerationConfig? = null

The configuration parameters to use for content generation.

safetySettings: List<SafetySetting>? = null

The safety bounds the model will abide to during content generation.

tools: List<Tool>? = null

A list of Tools the model may use to generate content.

toolConfig: ToolConfig? = null

The ToolConfig that defines how the model handles the tools provided.

systemInstruction: Content? = null

Content instructions that direct the model to behave a certain way. Currently only text content is supported.

requestOptions: RequestOptions = RequestOptions()

Configuration options for sending requests to the backend.

Returns
GenerativeModel

The initialized GenerativeModel instance.

imagenModel

@PublicPreviewAPI
fun imagenModel(
    modelName: String,
    generationConfig: ImagenGenerationConfig? = null,
    safetySettings: ImagenSafetySettings? = null,
    requestOptions: RequestOptions = RequestOptions()
): ImagenModel

Instantiates a new ImagenModel given the provided parameters.

Parameters
modelName: String

The name of the model to use. See the documentation for a list of supported models.

generationConfig: ImagenGenerationConfig? = null

The configuration parameters to use for image generation.

safetySettings: ImagenSafetySettings? = null

The safety bounds the model will abide by during image generation.

requestOptions: RequestOptions = RequestOptions()

Configuration options for sending requests to the backend.

Returns
ImagenModel

The initialized ImagenModel instance.

liveModel

@PublicPreviewAPI
fun liveModel(
    modelName: String,
    generationConfig: LiveGenerationConfig? = null,
    tools: List<Tool>? = null,
    systemInstruction: Content? = null,
    requestOptions: RequestOptions = RequestOptions()
): LiveGenerativeModel

Instantiates a new LiveGenerationConfig given the provided parameters.

Parameters
modelName: String

The name of the model to use. See the documentation for a list of supported models.

generationConfig: LiveGenerationConfig? = null

The configuration parameters to use for content generation.

tools: List<Tool>? = null

A list of Tools the model may use to generate content.

systemInstruction: Content? = null

Content instructions that direct the model to behave a certain way. Currently only text content is supported.

requestOptions: RequestOptions = RequestOptions()

Configuration options for sending requests to the backend.

Returns
LiveGenerativeModel

The initialized LiveGenerativeModel instance.