TemplateGenerativeModel

@PublicPreviewAPI
public final class TemplateGenerativeModel


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

Summary

Public methods

final @NonNull GenerateContentResponse
generateContent(
    @NonNull String templateId,
    @NonNull Map<@NonNull String, @NonNull Object> inputs
)

Generates content from a prompt template and inputs.

final @NonNull Flow<@NonNull GenerateContentResponse>
generateContentStream(
    @NonNull String templateId,
    @NonNull Map<@NonNull String, @NonNull Object> inputs
)

Generates content as a stream from a prompt template and inputs.

final @NonNull TemplateChat
@PublicPreviewAPI
startChat(
    @NonNull String templateId,
    @NonNull Map<@NonNull String, @NonNull Object> inputs,
    @NonNull List<@NonNull Content> history
)

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

Public methods

generateContent

public final @NonNull GenerateContentResponse generateContent(
    @NonNull String templateId,
    @NonNull Map<@NonNull String, @NonNull Object> inputs
)

Generates content from a prompt template and inputs.

Parameters
@NonNull String templateId

The ID of the prompt template to use.

@NonNull Map<@NonNull String, @NonNull Object> inputs

A map of variables to substitute into the template.

Returns
@NonNull GenerateContentResponse

The content generated by the model.

Throws
com.google.firebase.ai.type.FirebaseAIException com.google.firebase.ai.type.FirebaseAIException

if the request failed.

See also
FirebaseAIException

for types of errors.

generateContentStream

public final @NonNull Flow<@NonNull GenerateContentResponsegenerateContentStream(
    @NonNull String templateId,
    @NonNull Map<@NonNull String, @NonNull Object> inputs
)

Generates content as a stream from a prompt template and inputs.

Parameters
@NonNull String templateId

The ID of the prompt template to use.

@NonNull Map<@NonNull String, @NonNull Object> inputs

A map of variables to substitute into the template.

Returns
@NonNull Flow<@NonNull GenerateContentResponse>

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

Throws
com.google.firebase.ai.type.FirebaseAIException com.google.firebase.ai.type.FirebaseAIException

if the request failed.

See also
FirebaseAIException

for types of errors.

startChat

@PublicPreviewAPI
public final @NonNull TemplateChat startChat(
    @NonNull String templateId,
    @NonNull Map<@NonNull String, @NonNull Object> inputs,
    @NonNull List<@NonNull Content> history
)

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

Parameters
@NonNull String templateId

The ID of the prompt template to use.

@NonNull Map<@NonNull String, @NonNull Object> inputs

A map of variables to substitute into the template for the session.

@NonNull List<@NonNull Content> history

Prior history in the conversation.

Returns
@NonNull TemplateChat

The initialized TemplateChat instance.