FirebaseAILogic Framework Reference

Classes

The following classes are available globally.

  • An object that represents a back-and-forth chat with a model, capturing the history and saving the context in memory between each message sent.

    Declaration

    Swift

    public final class Chat : Sendable
  • The Firebase AI SDK provides access to Gemini models directly from your app.

    Declaration

    Swift

    public final class FirebaseAI : Sendable
  • A type that represents a remote multimodal model (like Gemini), with the ability to generate content based on various input types.

    Declaration

    Swift

    public final class GenerativeModel : Sendable
  • A session that handles multi-turn interactions with a generative model, similar to Chat.

    A GenerativeModelSession retains history between requests. For single-turn requests to a model, use generativeModelSession(model:instructions:) to start a new session. GenerativeModelSession is particularly useful for generating structured data.

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

    Example usage:

    @Generable
    struct UserProfile {
      @Guide(description: "A unique username for the user.")
      var username: String
    
      @Guide(description: "A short bio about the user, no more than 100 characters.")
      var bio: String
    
      @Guide(description: "A list of the user's favorite topics.", .count(3))
      var favoriteTopics: [String]
    }
    
    let firebaseAI = // ... a `FirebaseAI` instance
    let session = firebaseAI.generativeModelSession(model: "gemini-model-name")
    let prompt = "Generate a user profile for a cat lover who enjoys hiking."
    let response = try await session.respond(to: prompt, generating: UserProfile.self)
    
    print("Username: \(response.content.username)")
    print("Bio: \(response.content.bio)")
    print("Favorite Topics: \(response.content.favoriteTopics.joined(separator: ", "))")
    

    Declaration

    Swift

    public final class GenerativeModelSession : 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.

    Declaration

    Swift

    public final class TemplateGenerativeModel : Sendable
  • A type that represents a remote image generation model (like Imagen), with the ability to generate images based on various input types.

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

    Declaration

    Swift

    public final class TemplateImagenModel : Sendable
  • Represents a remote Imagen model with the ability to generate images using text prompts.

    See the generate images documentation for more details about the image generation capabilities offered by the Imagen model in the Firebase AI SDK SDK.

    Declaration

    Swift

    public final class ImagenModel
  • A multimodal model (like Gemini) capable of real-time content generation based on various input types, supporting bidirectional streaming.

    You can create a new session via connect().

    Declaration

    Swift

    @available(watchOS, unavailable)
    public final class LiveGenerativeModel
  • A live WebSocket session, capable of streaming content to and from the model.

    Messages are streamed through responses, and can be sent through either the dedicated realtime API function (such as sendAudioRealtime(_:) and sendTextRealtime(_:)), or through the incremental API (such as sendContent(_:turnComplete:)).

    To create an instance of this class, see LiveGenerativeModel.

    Declaration

    Swift

    @available(watchOS, unavailable)
    public final class LiveSession : Sendable
  • A Schema object allows the definition of input and output data types.

    These types can be objects, but also primitives and arrays. Represents a select subset of an OpenAPI 3.0 schema object.

    Declaration

    Swift

    public final class Schema : Sendable
    extension Schema: Encodable