Skip to content

Commit

Permalink
[Vertex AI] Add support for compiling on watchOS (#13215)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard authored Jul 2, 2024
1 parent 5362cc2 commit 102ae79
Show file tree
Hide file tree
Showing 28 changed files with 182 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/vertexai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
spm-unit:
strategy:
matrix:
target: [iOS, macOS, catalyst, tvOS, visionOS]
target: [iOS, macOS, catalyst, tvOS, visionOS, watchOS]
os: [macos-14]
include:
- os: macos-14
Expand Down
3 changes: 3 additions & 0 deletions FirebaseVertexAI/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 10.29.0
- [feature] Added community support for watchOS. (#13215)

# 10.28.0
- [changed] Removed uses of the `gemini-1.5-flash-preview-0514` model in docs
and samples. Developers should now use the auto-updated versions,
Expand Down
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Sources/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public class Chat {
private let model: GenerativeModel

Expand Down
10 changes: 5 additions & 5 deletions FirebaseVertexAI/Sources/CountTokensRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

import Foundation

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
struct CountTokensRequest {
let model: String
let contents: [ModelContent]
let options: RequestOptions
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension CountTokensRequest: GenerativeAIRequest {
typealias Response = CountTokensResponse

Expand All @@ -31,7 +31,7 @@ extension CountTokensRequest: GenerativeAIRequest {
}

/// The model's response to a count tokens request.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct CountTokensResponse {
/// The total number of tokens in the input given to the model as a prompt.
public let totalTokens: Int
Expand All @@ -45,14 +45,14 @@ public struct CountTokensResponse {

// MARK: - Codable Conformances

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension CountTokensRequest: Encodable {
enum CodingKeys: CodingKey {
case contents
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension CountTokensResponse: Decodable {
enum CodingKeys: CodingKey {
case totalTokens
Expand Down
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Sources/GenerateContentError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import Foundation

/// Errors that occur when generating content from a model.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public enum GenerateContentError: Error {
/// An error occurred when constructing the prompt. Examine the related error for details.
case promptImageContentError(underlying: ImageConversionError)
Expand Down
6 changes: 3 additions & 3 deletions FirebaseVertexAI/Sources/GenerateContentRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import Foundation

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

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension GenerateContentRequest: Encodable {
enum CodingKeys: String, CodingKey {
case contents
Expand All @@ -40,7 +40,7 @@ extension GenerateContentRequest: Encodable {
}
}

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

Expand Down
28 changes: 14 additions & 14 deletions FirebaseVertexAI/Sources/GenerateContentResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import Foundation

/// The model's response to a generate content request.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct GenerateContentResponse {
/// Token usage metadata for processing the generate content request.
public struct UsageMetadata {
Expand Down Expand Up @@ -84,7 +84,7 @@ public struct GenerateContentResponse {

/// 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 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct CandidateResponse {
/// The response's content.
public let content: ModelContent
Expand All @@ -110,14 +110,14 @@ public struct CandidateResponse {
}

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

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

/// A value enumerating possible reasons for a model to terminate a content generation request.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public enum FinishReason: String {
case unknown = "FINISH_REASON_UNKNOWN"

Expand All @@ -158,7 +158,7 @@ public enum FinishReason: String {
}

/// A metadata struct containing any feedback the model had on the prompt it was provided.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct PromptFeedback {
/// A type describing possible reasons to block a prompt.
public enum BlockReason: String {
Expand Down Expand Up @@ -190,7 +190,7 @@ public struct PromptFeedback {

// MARK: - Codable Conformances

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

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension GenerateContentResponse.UsageMetadata: Decodable {
enum CodingKeys: CodingKey {
case promptTokenCount
Expand All @@ -241,7 +241,7 @@ extension GenerateContentResponse.UsageMetadata: Decodable {
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension CandidateResponse: Decodable {
enum CodingKeys: CodingKey {
case content
Expand Down Expand Up @@ -290,14 +290,14 @@ extension CandidateResponse: Decodable {
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension CitationMetadata: Decodable {
enum CodingKeys: String, CodingKey {
case citationSources = "citations"
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension Citation: Decodable {
enum CodingKeys: CodingKey {
case startIndex
Expand All @@ -315,7 +315,7 @@ extension Citation: Decodable {
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension FinishReason: Decodable {
public init(from decoder: Decoder) throws {
let value = try decoder.singleValueContainer().decode(String.self)
Expand All @@ -330,7 +330,7 @@ extension FinishReason: Decodable {
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension PromptFeedback.BlockReason: Decodable {
public init(from decoder: Decoder) throws {
let value = try decoder.singleValueContainer().decode(String.self)
Expand All @@ -345,7 +345,7 @@ extension PromptFeedback.BlockReason: Decodable {
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension PromptFeedback: Decodable {
enum CodingKeys: CodingKey {
case blockReason
Expand Down
4 changes: 2 additions & 2 deletions FirebaseVertexAI/Sources/GenerationConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Foundation

/// A struct defining model parameters to be used when sending generative AI
/// requests to the backend model.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct GenerationConfig {
/// A parameter controlling the degree of randomness in token selection. A
/// temperature of zero is deterministic, always choosing the
Expand Down Expand Up @@ -95,5 +95,5 @@ public struct GenerationConfig {

// MARK: - Codable Conformances

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension GenerationConfig: Encodable {}
4 changes: 2 additions & 2 deletions FirebaseVertexAI/Sources/GenerativeAIRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import Foundation

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

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

/// Configuration parameters for sending requests to the backend.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct RequestOptions {
/// The request’s timeout interval in seconds; if not specified uses the default value for a
/// `URLRequest`.
Expand Down
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Sources/GenerativeAIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import FirebaseAuthInterop
import FirebaseCore
import Foundation

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.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 Down
4 changes: 2 additions & 2 deletions FirebaseVertexAI/Sources/GenerativeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation

/// A type that represents a remote multimodal model (like Gemini), with the ability to generate
/// content based on various input types.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public final class GenerativeModel {
// The prefix for a model resource in the Gemini API.
private static let modelResourcePrefix = "models/"
Expand Down Expand Up @@ -318,7 +318,7 @@ public final class GenerativeModel {
}

/// An error thrown in `GenerativeModel.countTokens(_:)`.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public enum CountTokensError: Error {
case internalError(underlying: Error)
}
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Sources/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import Foundation
import OSLog

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
struct Logging {
/// Subsystem that should be used for all Loggers.
static let subsystem = "com.google.firebase.vertex-ai"
Expand Down
6 changes: 3 additions & 3 deletions FirebaseVertexAI/Sources/ModelContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Foundation
/// A type describing data in media formats interpretable by an AI model. Each generative AI
/// request or response contains an `Array` of ``ModelContent``s, and each ``ModelContent`` value
/// may comprise multiple heterogeneous ``ModelContent/Part``s.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public struct ModelContent: Equatable {
/// A discrete piece of data in a media format interpretable by an AI model. Within a single value
/// of ``Part``, different data types may not mix.
Expand Down Expand Up @@ -116,10 +116,10 @@ public struct ModelContent: Equatable {

// MARK: Codable Conformances

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension ModelContent: Codable {}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
extension ModelContent.Part: Codable {
enum CodingKeys: String, CodingKey {
case text
Expand Down
Loading

0 comments on commit 102ae79

Please sign in to comment.