Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions FirebaseAI.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Build AI-powered apps and features with the Gemini API using the Firebase AI SDK
s.social_media_url = 'https://twitter.com/Firebase'

ios_deployment_target = '15.0'
osx_deployment_target = '12.0'
osx_deployment_target = '10.15'
tvos_deployment_target = '15.0'
watchos_deployment_target = '8.0'
watchos_deployment_target = '7.0'

s.ios.deployment_target = ios_deployment_target
s.osx.deployment_target = osx_deployment_target
Expand Down
1 change: 0 additions & 1 deletion FirebaseAI/Sources/AILog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ enum AILog {
log(level: .debug, code: code, message)
}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
static func makeInternalError(message: String, code: MessageCode) -> GenerateContentError {
let error = GenerateContentError.internalError(underlying: NSError(
domain: "\(Constants.baseErrorDomain).Internal",
Expand Down
6 changes: 3 additions & 3 deletions FirebaseAI/Sources/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Foundation

/// 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.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public final class Chat: Sendable {
private let model: GenerativeModel
private let _history: History
Expand Down Expand Up @@ -62,7 +61,7 @@ public final class Chat: Sendable {
/// and response will be added to the history. If unsuccessful, history will remain unchanged.
/// - Parameter parts: The new content to send as a single chat message.
/// - Returns: A stream containing the model's response or an error if an error occurred.
@available(macOS 12.0, *)
@available(macOS 12.0, watchOS 8.0, *)
public func sendMessageStream(_ parts: any PartsRepresentable...) throws
-> AsyncThrowingStream<GenerateContentResponse, Error> {
return try sendMessageStream([ModelContent(parts: parts)])
Expand All @@ -72,7 +71,7 @@ public final class Chat: Sendable {
/// and response will be added to the history. If unsuccessful, history will remain unchanged.
/// - Parameter content: The new content to send as a single chat message.
/// - Returns: A stream containing the model's response or an error if an error occurred.
@available(macOS 12.0, *)
@available(macOS 12.0, watchOS 8.0, *)
public func sendMessageStream(_ content: [ModelContent]) throws
-> AsyncThrowingStream<GenerateContentResponse, Error> {
return try sendMessageStream(content, generationConfig: generationConfig)
Expand Down Expand Up @@ -106,6 +105,7 @@ public final class Chat: Sendable {
return result
}

@available(macOS 12.0, watchOS 8.0, *)
func sendMessageStream(_ content: [ModelContent], generationConfig: GenerationConfig?) throws
-> AsyncThrowingStream<GenerateContentResponse, Error> {
// Ensure that the new content has the role set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import Foundation

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension FirebaseAI.GenerationSchema {
/// Returns a Gemini-compatible JSON Schema of this `GenerationSchema`.
func toGeminiJSONSchema() throws -> JSONObject {
Expand Down
2 changes: 0 additions & 2 deletions FirebaseAI/Sources/FirebaseAI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import Foundation
internal import FirebaseCoreExtension

/// The Firebase AI SDK provides access to Gemini models directly from your app.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public final class FirebaseAI: Sendable {
// MARK: - Public APIs

Expand Down Expand Up @@ -197,7 +196,6 @@ public final class FirebaseAI: Sendable {
/// - systemInstruction: Instructions that direct the model to behave a certain way; currently
/// only text content is supported.
/// - requestOptions: Configuration parameters for sending requests to the backend.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *)
@available(watchOS, unavailable)
public func liveModel(modelName: String,
generationConfig: LiveGenerationConfig? = nil,
Expand Down
1 change: 0 additions & 1 deletion FirebaseAI/Sources/FirebaseInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Foundation
@preconcurrency import FirebaseCore

/// Firebase data used by FirebaseAI
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
struct FirebaseInfo: Sendable {
let appCheck: AppCheckInterop?
let auth: AuthInterop?
Expand Down
1 change: 0 additions & 1 deletion FirebaseAI/Sources/GenerateContentError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import Foundation

/// Errors that occur when generating content from a model.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public enum GenerateContentError: Error {
/// An internal error occurred. See the underlying error for more context.
case internalError(underlying: Error)
Expand Down
4 changes: 0 additions & 4 deletions FirebaseAI/Sources/GenerateContentRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import Foundation

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
struct GenerateContentRequest: Sendable {
/// Model name.
let model: String
Expand All @@ -31,7 +30,6 @@ struct GenerateContentRequest: Sendable {
let options: RequestOptions
}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension GenerateContentRequest: Encodable {
enum CodingKeys: String, CodingKey {
case model
Expand Down Expand Up @@ -60,7 +58,6 @@ extension GenerateContentRequest: Encodable {
}
}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension GenerateContentRequest {
enum APIMethod: String {
case generateContent
Expand All @@ -69,7 +66,6 @@ extension GenerateContentRequest {
}
}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension GenerateContentRequest: GenerativeAIRequest {
typealias Response = GenerateContentResponse

Expand Down
26 changes: 0 additions & 26 deletions FirebaseAI/Sources/GenerateContentResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
import Foundation

/// The model's response to a generate content request.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct GenerateContentResponse: Sendable {
/// Token usage metadata for processing the generate content request.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct UsageMetadata: Sendable {
/// The number of tokens in the request prompt.
public let promptTokenCount: Int
Expand Down Expand Up @@ -155,7 +153,6 @@ public struct GenerateContentResponse: Sendable {

/// A struct representing a possible reply to a content generation prompt. Each content generation
/// prompt may produce multiple candidate responses.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct Candidate: Sendable {
/// The response's content.
public let content: ModelContent
Expand Down Expand Up @@ -196,14 +193,12 @@ public struct Candidate: Sendable {
}

/// A collection of source attributions for a piece of content.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct CitationMetadata: Sendable {
/// A list of individual cited sources and the parts of the content to which they apply.
public let citations: [Citation]
}

/// A struct describing a source attribution.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct Citation: Sendable, Equatable {
/// The inclusive beginning of a sequence in a model response that derives from a cited source.
public let startIndex: Int
Expand Down Expand Up @@ -241,7 +236,6 @@ public struct Citation: Sendable, Equatable {
}

/// A value enumerating possible reasons for a model to terminate a content generation request.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct FinishReason: DecodableProtoEnum, Hashable, Sendable {
enum Kind: String {
case stop = "STOP"
Expand Down Expand Up @@ -296,10 +290,8 @@ public struct FinishReason: DecodableProtoEnum, Hashable, Sendable {
}

/// A metadata struct containing any feedback the model had on the prompt it was provided.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct PromptFeedback: Sendable {
/// A type describing possible reasons to block a prompt.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct BlockReason: DecodableProtoEnum, Hashable, Sendable {
enum Kind: String {
case safety = "SAFETY"
Expand Down Expand Up @@ -355,7 +347,6 @@ public struct PromptFeedback: Sendable {
/// [Gemini Developer API](https://ai.google.dev/gemini-api/terms#grounding-with-google-search)
/// or Vertex AI Gemini API (see [Service Terms](https://cloud.google.com/terms/service-terms)
/// section within the Service Specific Terms).
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct GroundingMetadata: Sendable, Equatable, Hashable {
/// A list of web search queries that the model performed to gather the grounding information.
/// These can be used to allow users to explore the search results themselves.
Expand All @@ -372,7 +363,6 @@ public struct GroundingMetadata: Sendable, Equatable, Hashable {
public let searchEntryPoint: SearchEntryPoint?

/// A struct representing the Google Search entry point.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct SearchEntryPoint: Sendable, Equatable, Hashable {
/// An HTML/CSS snippet that can be embedded in your app.
///
Expand All @@ -382,14 +372,12 @@ public struct GroundingMetadata: Sendable, Equatable, Hashable {

/// Represents a chunk of retrieved data that supports a claim in the model's response. This is
/// part of the grounding information provided when grounding is enabled.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct GroundingChunk: Sendable, Equatable, Hashable {
/// Contains details if the grounding chunk is from a web source.
public let web: WebGroundingChunk?
}

/// A grounding chunk sourced from the web.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct WebGroundingChunk: Sendable, Equatable, Hashable {
/// The URI of the retrieved web page.
public let uri: String?
Expand All @@ -403,7 +391,6 @@ public struct GroundingMetadata: Sendable, Equatable, Hashable {

/// Provides information about how a specific segment of the model's response is supported by the
/// retrieved grounding chunks.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct GroundingSupport: Sendable, Equatable, Hashable {
/// Specifies the segment of the model's response content that this grounding support pertains
/// to.
Expand Down Expand Up @@ -436,7 +423,6 @@ public struct GroundingMetadata: Sendable, Equatable, Hashable {

/// Represents a specific segment within a ``ModelContent`` struct, often used to pinpoint the
/// exact location of text or data that grounding information refers to.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct Segment: Sendable, Equatable, Hashable {
/// The zero-based index of the ``Part`` object within the `parts` array of its parent
/// ``ModelContent`` object. This identifies which part of the content the segment belongs to.
Expand All @@ -454,7 +440,6 @@ public struct Segment: Sendable, Equatable, Hashable {

// MARK: - Codable Conformances

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension GenerateContentResponse: Decodable {
enum CodingKeys: String, CodingKey {
case candidates
Expand Down Expand Up @@ -490,7 +475,6 @@ extension GenerateContentResponse: Decodable {
}
}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension GenerateContentResponse.UsageMetadata: Decodable {
enum CodingKeys: CodingKey {
case promptTokenCount
Expand Down Expand Up @@ -532,7 +516,6 @@ extension GenerateContentResponse.UsageMetadata: Decodable {
}
}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension Candidate: Decodable {
enum CodingKeys: CodingKey {
case content
Expand Down Expand Up @@ -593,7 +576,6 @@ extension Candidate: Decodable {
}
}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension CitationMetadata: Decodable {
enum CodingKeys: CodingKey {
case citations // Vertex AI
Expand All @@ -612,7 +594,6 @@ extension CitationMetadata: Decodable {
}
}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension Citation: Decodable {
enum CodingKeys: CodingKey {
case startIndex
Expand Down Expand Up @@ -664,7 +645,6 @@ extension Citation: Decodable {
}
}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension PromptFeedback: Decodable {
enum CodingKeys: CodingKey {
case blockReason
Expand All @@ -690,7 +670,6 @@ extension PromptFeedback: Decodable {
}
}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension GroundingMetadata: Decodable {
enum CodingKeys: String, CodingKey {
case webSearchQueries
Expand All @@ -717,16 +696,12 @@ extension GroundingMetadata: Decodable {
}
}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension GroundingMetadata.SearchEntryPoint: Decodable {}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension GroundingMetadata.GroundingChunk: Decodable {}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension GroundingMetadata.WebGroundingChunk: Decodable {}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension GroundingMetadata.GroundingSupport.Internal: Decodable {
enum CodingKeys: String, CodingKey {
case segment
Expand All @@ -743,7 +718,6 @@ extension GroundingMetadata.GroundingSupport.Internal: Decodable {
}
}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension Segment: Decodable {
enum CodingKeys: String, CodingKey {
case partIndex
Expand Down
2 changes: 0 additions & 2 deletions FirebaseAI/Sources/GenerationConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Foundation

/// A struct defining model parameters to be used when sending generative AI
/// requests to the backend model.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct GenerationConfig: Sendable {
/// Controls the degree of randomness in token selection.
var temperature: Float?
Expand Down Expand Up @@ -255,7 +254,6 @@ public struct GenerationConfig: Sendable {

// MARK: - Codable Conformances

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension GenerationConfig: Encodable {
enum CodingKeys: String, CodingKey {
case temperature
Expand Down
3 changes: 0 additions & 3 deletions FirebaseAI/Sources/GenerativeAIRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import Foundation

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
protocol GenerativeAIRequest: Sendable, Encodable {
associatedtype Response: Sendable, Decodable

Expand All @@ -24,7 +23,6 @@ protocol GenerativeAIRequest: Sendable, Encodable {
}

/// Configuration parameters for sending requests to the backend.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct RequestOptions: Sendable {
/// The request’s timeout interval in seconds; if not specified uses the default value for a
/// `URLRequest`.
Expand All @@ -39,5 +37,4 @@ public struct RequestOptions: Sendable {
}
}

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension RequestOptions: Equatable {}
9 changes: 6 additions & 3 deletions FirebaseAI/Sources/GenerativeAIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import FirebaseCore
import Foundation
import os.log

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
struct GenerativeAIService {
/// The language of the SDK in the format `gl-<language>/<version>`.
static let languageTag = "gl-swift/5"
Expand All @@ -39,7 +38,9 @@ struct GenerativeAIService {
let urlRequest = try await urlRequest(request: request)

#if DEBUG
printCURLCommand(from: urlRequest)
if #available(macOS 11.0, *) {
printCURLCommand(from: urlRequest)
}
#endif

let data: Data
Expand Down Expand Up @@ -67,7 +68,7 @@ struct GenerativeAIService {
return try parseResponse(T.Response.self, from: data)
}

@available(macOS 12.0, *)
@available(macOS 12.0, watchOS 8.0, *)
func loadRequestStream<T: GenerativeAIRequest>(request: T)
-> AsyncThrowingStream<T.Response, Error> where T: Sendable {
return AsyncThrowingStream { continuation in
Expand Down Expand Up @@ -301,6 +302,7 @@ struct GenerativeAIService {
}

#if DEBUG
@available(macOS 11.0, *)
private func cURLCommand(from request: URLRequest) -> String {
var returnValue = "curl "
if let allHeaders = request.allHTTPHeaderFields {
Expand All @@ -320,6 +322,7 @@ struct GenerativeAIService {
return returnValue
}

@available(macOS 11.0, *)
private func printCURLCommand(from request: URLRequest) {
guard AILog.additionalLoggingEnabled() else {
return
Expand Down
Loading
Loading