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
GenerativeModelSessionretains history between requests. For single-turn requests to a model, usegenerativeModelSession(model:tools:instructions:)to start a new session.GenerativeModelSessionis 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 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
LiveGenerativeModel/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 assendAudioRealtime(_:)andsendTextRealtime(_:)), or through the incremental API (such assendContent(_:turnComplete:)).To create an instance of this class, see
LiveGenerativeModel.Declaration
Swift
@available(watchOS, unavailable) public final class LiveSession : Sendable -
A
Schemaobject 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 : Sendableextension Schema: Encodableextension Schema: Equatable