Skip to content

Commit

Permalink
Add support to watchOS from 7.0 (or at least fixing build errors)
Browse files Browse the repository at this point in the history
  • Loading branch information
rin-senpai committed Jun 28, 2024
1 parent 5478400 commit a786f63
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Sources/GoogleAI/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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
public class Chat {
private let model: GenerativeModel

Expand Down
10 changes: 5 additions & 5 deletions Sources/GoogleAI/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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
struct CountTokensRequest {
let model: String
let generateContentRequest: GenerateContentRequest
let options: RequestOptions
}

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

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

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

// MARK: - Codable Conformances

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

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
extension CountTokensResponse: Decodable {}
2 changes: 1 addition & 1 deletion Sources/GoogleAI/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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.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 Sources/GoogleAI/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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
extension GenerateContentRequest: Encodable {
enum CodingKeys: String, CodingKey {
case model
Expand All @@ -41,7 +41,7 @@ extension GenerateContentRequest: Encodable {
}
}

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

Expand Down
28 changes: 14 additions & 14 deletions Sources/GoogleAI/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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
public struct GenerateContentResponse {
/// Token usage metadata for processing the generate content request.
public struct UsageMetadata {
Expand Down Expand Up @@ -82,7 +82,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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
public struct CandidateResponse {
/// The response's content.
public let content: ModelContent
Expand All @@ -108,14 +108,14 @@ public struct CandidateResponse {
}

/// A collection of source attributions for a piece of content.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.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 @@ -131,7 +131,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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
public enum FinishReason: String {
case unknown = "FINISH_REASON_UNKNOWN"

Expand All @@ -156,7 +156,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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
public struct PromptFeedback {
/// A type describing possible reasons to block a prompt.
public enum BlockReason: String {
Expand Down Expand Up @@ -188,7 +188,7 @@ public struct PromptFeedback {

// MARK: - Codable Conformances

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

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

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

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
extension CitationMetadata: Decodable {}

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

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

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

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
extension PromptFeedback: Decodable {
enum CodingKeys: CodingKey {
case blockReason
Expand Down
4 changes: 2 additions & 2 deletions Sources/GoogleAI/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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.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 @@ -106,5 +106,5 @@ public struct GenerationConfig {

// MARK: - Codable Conformances

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
extension GenerationConfig: Encodable {}
4 changes: 2 additions & 2 deletions Sources/GoogleAI/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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
public struct RequestOptions {
/// The request’s timeout interval in seconds.
let timeout: TimeInterval
Expand Down
2 changes: 1 addition & 1 deletion Sources/GoogleAI/GenerativeAIService.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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
struct GenerativeAIService {
/// Gives permission to talk to the backend.
private let apiKey: String
Expand Down
2 changes: 1 addition & 1 deletion Sources/GoogleAI/GenerativeAISwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
#endif

/// Constants associated with the GenerativeAISwift SDK.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
public enum GenerativeAISwift {
/// String value of the SDK version
public static let version = "0.5.4"
Expand Down
4 changes: 2 additions & 2 deletions Sources/GoogleAI/GenerativeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
public final class GenerativeModel {
// The prefix for a model resource in the Gemini API.
private static let modelResourcePrefix = "models/"
Expand Down Expand Up @@ -370,7 +370,7 @@ public final class GenerativeModel {
}

/// An error thrown in `GenerativeModel.countTokens(_:)`.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
public enum CountTokensError: Error {
case internalError(underlying: Error)
}
2 changes: 1 addition & 1 deletion Sources/GoogleAI/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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
struct Logging {
/// Subsystem that should be used for all Loggers.
static let subsystem = "com.google.generative-ai"
Expand Down
6 changes: 3 additions & 3 deletions Sources/GoogleAI/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, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
public struct ModelContent: Equatable {
/// A discrete piece of data in a media format intepretable by an AI model. Within a single value
/// of ``Part``, different data types may not mix.
Expand Down Expand Up @@ -118,10 +118,10 @@ public struct ModelContent: Equatable {

// MARK: Codable Conformances

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

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
extension ModelContent.Part: Codable {
enum CodingKeys: String, CodingKey {
case text
Expand Down
8 changes: 4 additions & 4 deletions Sources/GoogleAI/PartsRepresentable+Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public enum ImageConversionError: Error {

#if canImport(UIKit)
/// Enables images to be representable as ``ThrowingPartsRepresentable``.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
extension UIImage: ThrowingPartsRepresentable {
public func tryPartsValue() throws -> [ModelContent.Part] {
guard let data = jpegData(compressionQuality: imageCompressionQuality) else {
Expand All @@ -50,7 +50,7 @@ public enum ImageConversionError: Error {

#elseif canImport(AppKit)
/// Enables images to be representable as ``ThrowingPartsRepresentable``.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
extension NSImage: ThrowingPartsRepresentable {
public func tryPartsValue() throws -> [ModelContent.Part] {
guard let cgImage = cgImage(forProposedRect: nil, context: nil, hints: nil) else {
Expand All @@ -67,7 +67,7 @@ public enum ImageConversionError: Error {
#endif

/// Enables `CGImages` to be representable as model content.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
extension CGImage: ThrowingPartsRepresentable {
public func tryPartsValue() throws -> [ModelContent.Part] {
let output = NSMutableData()
Expand All @@ -88,7 +88,7 @@ extension CGImage: ThrowingPartsRepresentable {
}

/// Enables `CIImages` to be representable as model content.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
extension CIImage: ThrowingPartsRepresentable {
public func tryPartsValue() throws -> [ModelContent.Part] {
let context = CIContext()
Expand Down
12 changes: 6 additions & 6 deletions Sources/GoogleAI/PartsRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ import Foundation

/// A protocol describing any data that could be serialized to model-interpretable input data,
/// where the serialization process might fail with an error.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
public protocol ThrowingPartsRepresentable {
func tryPartsValue() throws -> [ModelContent.Part]
}

/// A protocol describing any data that could be serialized to model-interpretable input data,
/// where the serialization process cannot fail with an error. For a failable conversion, see
/// ``ThrowingPartsRepresentable``
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
public protocol PartsRepresentable: ThrowingPartsRepresentable {
var partsValue: [ModelContent.Part] { get }
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
public extension PartsRepresentable {
func tryPartsValue() throws -> [ModelContent.Part] {
return partsValue
}
}

/// Enables a ``ModelContent.Part`` to be passed in as ``ThrowingPartsRepresentable``.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
extension ModelContent.Part: ThrowingPartsRepresentable {
public typealias ErrorType = Never
public func tryPartsValue() throws -> [ModelContent.Part] {
Expand All @@ -47,7 +47,7 @@ extension ModelContent.Part: ThrowingPartsRepresentable {

/// Enable an `Array` of ``ThrowingPartsRepresentable`` values to be passed in as a single
/// ``ThrowingPartsRepresentable``.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
extension [ThrowingPartsRepresentable]: ThrowingPartsRepresentable {
public func tryPartsValue() throws -> [ModelContent.Part] {
return try compactMap { element in
Expand All @@ -58,7 +58,7 @@ extension [ThrowingPartsRepresentable]: ThrowingPartsRepresentable {
}

/// Enables a `String` to be passed in as ``ThrowingPartsRepresentable``.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
extension String: PartsRepresentable {
public var partsValue: [ModelContent.Part] {
return [.text(self)]
Expand Down
Loading

0 comments on commit a786f63

Please sign in to comment.