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.

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.