FirebaseAILogic Framework Reference

TemplateGenerativeModel

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
public final class TemplateGenerativeModel : Sendable

A type that represents a remote multimodal model (like Gemini), with the ability to generate content based on various input types.

Public Preview: This API is a public preview and may be subject to change.

  • Generates content from a prompt template and inputs.

    Public Preview: This API is a public preview and may be subject to change.

    Throws

    A GenerateContentError if the request failed.

    Declaration

    Swift

    public func generateContent(templateID: String,
                                inputs: [String: Any],
                                options: RequestOptions = RequestOptions()) async throws
      -> GenerateContentResponse

    Parameters

    templateID

    The ID of the prompt template to use.

    inputs

    A dictionary of variables to substitute into the template.

    options

    The RequestOptions for the request, currently used to override default request timeout.

    Return Value

    The content generated by the model.

  • Generates content from a prompt template and inputs, with streaming responses.

    Public Preview: This API is a public preview and may be subject to change.

    Throws

    A GenerateContentError if the request failed.

    Declaration

    Swift

    public func generateContentStream(templateID: String,
                                      inputs: [String: Any],
                                      options: RequestOptions = RequestOptions()) throws
      -> AsyncThrowingStream<GenerateContentResponse, Error>

    Parameters

    templateID

    The ID of the prompt template to use.

    inputs

    A dictionary of variables to substitute into the template.

    options

    The RequestOptions for the request, currently used to override default request timeout.

    Return Value

    An AsyncThrowingStream that yields GenerateContentResponse objects.