Skip to content

Commit 9a5df1b

Browse files
committed
Used watchOS 4.0 as a baseline and updated function requirements as such
1 parent 646da8e commit 9a5df1b

19 files changed

+69
-64
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let package = Package(
2323
.iOS(.v11),
2424
.macOS(.v10_13),
2525
.macCatalyst(.v13),
26-
.watchOS(.v8)
26+
.watchOS(.v4)
2727
],
2828
products: [
2929
.library(

Sources/GoogleAI/Chat.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class Chat {
8484
/// and response will be added to the history. If unsuccessful, history will remain unchanged.
8585
/// - Parameter parts: The new content to send as a single chat message.
8686
/// - Returns: A stream containing the model's response or an error if an error occurred.
87-
@available(macOS 12.0, *)
87+
@available(macOS 12.0, watchOS 8.0, *)
8888
public func sendMessageStream(_ parts: any ThrowingPartsRepresentable...)
8989
-> AsyncThrowingStream<GenerateContentResponse, Error> {
9090
return try sendMessageStream([ModelContent(parts: parts)])
@@ -94,7 +94,7 @@ public class Chat {
9494
/// and response will be added to the history. If unsuccessful, history will remain unchanged.
9595
/// - Parameter content: The new content to send as a single chat message.
9696
/// - Returns: A stream containing the model's response or an error if an error occurred.
97-
@available(macOS 12.0, *)
97+
@available(macOS 12.0, watchOS 8.0, *)
9898
public func sendMessageStream(_ content: @autoclosure () throws -> [ModelContent])
9999
-> AsyncThrowingStream<GenerateContentResponse, Error> {
100100
let resolvedContent: [ModelContent]
@@ -188,4 +188,4 @@ public class Chat {
188188
return ModelContent(role: "user", parts: content.parts)
189189
}
190190
}
191-
}
191+
}

Sources/GoogleAI/CountTokensRequest.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
import Foundation
1616

17-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
17+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
1818
struct CountTokensRequest {
1919
let model: String
2020
let generateContentRequest: GenerateContentRequest
2121
let options: RequestOptions
2222
}
2323

24-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
24+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
2525
extension CountTokensRequest: GenerativeAIRequest {
2626
typealias Response = CountTokensResponse
2727

@@ -31,20 +31,20 @@ extension CountTokensRequest: GenerativeAIRequest {
3131
}
3232

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

4040
// MARK: - Codable Conformances
4141

42-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
42+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
4343
extension CountTokensRequest: Encodable {
4444
enum CodingKeys: CodingKey {
4545
case generateContentRequest
4646
}
4747
}
4848

49-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
50-
extension CountTokensResponse: Decodable {}
49+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
50+
extension CountTokensResponse: Decodable {}

Sources/GoogleAI/Errors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,4 @@ enum RPCErrorMessage: String {
186186
enum InvalidCandidateError: Error {
187187
case emptyContent(underlyingError: Error)
188188
case malformedContent(underlyingError: Error)
189-
}
189+
}

Sources/GoogleAI/FunctionCalling.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,4 @@ extension FunctionCallingConfig.Mode: Encodable {}
292292

293293
extension ToolConfig: Encodable {}
294294

295-
extension FunctionResponse: Encodable {}
295+
extension FunctionResponse: Encodable {}

Sources/GoogleAI/GenerateContentError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ public enum GenerateContentError: Error {
4141
/// - Important: The API is only available in
4242
/// [specific regions](https://ai.google.dev/available_regions#available_regions).
4343
case unsupportedUserLocation
44-
}
44+
}

Sources/GoogleAI/GenerateContentRequest.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import Foundation
1616

17-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
17+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
1818
struct GenerateContentRequest {
1919
/// Model name.
2020
let model: String
@@ -28,7 +28,7 @@ struct GenerateContentRequest {
2828
let options: RequestOptions
2929
}
3030

31-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
31+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
3232
extension GenerateContentRequest: Encodable {
3333
enum CodingKeys: String, CodingKey {
3434
case model
@@ -53,4 +53,4 @@ extension GenerateContentRequest: GenerativeAIRequest {
5353
return URL(string: "\(modelURL):generateContent")!
5454
}
5555
}
56-
}
56+
}

Sources/GoogleAI/GenerateContentResponse.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public struct GenerateContentResponse {
8282

8383
/// A struct representing a possible reply to a content generation prompt. Each content generation
8484
/// prompt may produce multiple candidate responses.
85-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
85+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
8686
public struct CandidateResponse {
8787
/// The response's content.
8888
public let content: ModelContent
@@ -108,14 +108,14 @@ public struct CandidateResponse {
108108
}
109109

110110
/// A collection of source attributions for a piece of content.
111-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
111+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
112112
public struct CitationMetadata {
113113
/// A list of individual cited sources and the parts of the content to which they apply.
114114
public let citationSources: [Citation]
115115
}
116116

117117
/// A struct describing a source attribution.
118-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
118+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
119119
public struct Citation {
120120
/// The inclusive beginning of a sequence in a model response that derives from a cited source.
121121
public let startIndex: Int
@@ -131,7 +131,7 @@ public struct Citation {
131131
}
132132

133133
/// A value enumerating possible reasons for a model to terminate a content generation request.
134-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
134+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
135135
public enum FinishReason: String {
136136
case unknown = "FINISH_REASON_UNKNOWN"
137137

@@ -156,7 +156,7 @@ public enum FinishReason: String {
156156
}
157157

158158
/// A metadata struct containing any feedback the model had on the prompt it was provided.
159-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
159+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
160160
public struct PromptFeedback {
161161
/// A type describing possible reasons to block a prompt.
162162
public enum BlockReason: String {
@@ -239,7 +239,7 @@ extension GenerateContentResponse.UsageMetadata: Decodable {
239239
}
240240
}
241241

242-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
242+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
243243
extension CandidateResponse: Decodable {
244244
enum CodingKeys: CodingKey {
245245
case content
@@ -286,10 +286,10 @@ extension CandidateResponse: Decodable {
286286
}
287287
}
288288

289-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
289+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
290290
extension CitationMetadata: Decodable {}
291291

292-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
292+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
293293
extension Citation: Decodable {
294294
enum CodingKeys: CodingKey {
295295
case startIndex
@@ -342,7 +342,7 @@ extension PromptFeedback.BlockReason: Decodable {
342342
}
343343
}
344344

345-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
345+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
346346
extension PromptFeedback: Decodable {
347347
enum CodingKeys: CodingKey {
348348
case blockReason
@@ -364,4 +364,4 @@ extension PromptFeedback: Decodable {
364364
safetyRatings = []
365365
}
366366
}
367-
}
367+
}

Sources/GoogleAI/GenerationConfig.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Foundation
1616

1717
/// A struct defining model parameters to be used when sending generative AI
1818
/// requests to the backend model.
19-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
19+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
2020
public struct GenerationConfig {
2121
/// A parameter controlling the degree of randomness in token selection. A
2222
/// temperature of zero is deterministic, always choosing the
@@ -106,5 +106,5 @@ public struct GenerationConfig {
106106

107107
// MARK: - Codable Conformances
108108

109-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
110-
extension GenerationConfig: Encodable {}
109+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
110+
extension GenerationConfig: Encodable {}

Sources/GoogleAI/GenerativeAIRequest.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import Foundation
1616

17-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
17+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
1818
protocol GenerativeAIRequest: Encodable {
1919
associatedtype Response: Decodable
2020

@@ -24,7 +24,7 @@ protocol GenerativeAIRequest: Encodable {
2424
}
2525

2626
/// Configuration parameters for sending requests to the backend.
27-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
27+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
2828
public struct RequestOptions {
2929
/// The request’s timeout interval in seconds.
3030
let timeout: TimeInterval
@@ -41,4 +41,4 @@ public struct RequestOptions {
4141
self.timeout = timeout
4242
self.apiVersion = apiVersion
4343
}
44-
}
44+
}

Sources/GoogleAI/GenerativeAIService.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct GenerativeAIService {
5252
return try parseResponse(T.Response.self, from: data)
5353
}
5454

55-
@available(macOS 12.0, *)
55+
@available(macOS 12.0, watchOS 8.0, *)
5656
func loadRequestStream<T: GenerativeAIRequest>(request: T)
5757
-> AsyncThrowingStream<T.Response, Error> {
5858
return AsyncThrowingStream { continuation in
@@ -161,6 +161,7 @@ struct GenerativeAIService {
161161
return urlRequest
162162
}
163163

164+
@available(watchOS 7.0, *)
164165
private func httpResponse(urlResponse: URLResponse) throws -> HTTPURLResponse {
165166
// Verify the status code is 200
166167
guard let response = urlResponse as? HTTPURLResponse else {
@@ -209,6 +210,7 @@ struct GenerativeAIService {
209210
}
210211
}
211212

213+
@available(watchOS 7.0, *)
212214
private func parseResponse<T: Decodable>(_ type: T.Type, from data: Data) throws -> T {
213215
do {
214216
return try JSONDecoder().decode(type, from: data)
@@ -222,6 +224,7 @@ struct GenerativeAIService {
222224
}
223225

224226
#if DEBUG
227+
@available(watchOS 7.0, *)
225228
private func cURLCommand(from request: URLRequest) -> String {
226229
var returnValue = "curl "
227230
if let allHeaders = request.allHTTPHeaderFields {
@@ -251,4 +254,4 @@ struct GenerativeAIService {
251254
""")
252255
}
253256
#endif // DEBUG
254-
}
257+
}

Sources/GoogleAI/GenerativeAISwift.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import Foundation
1818
#endif
1919

2020
/// Constants associated with the GenerativeAISwift SDK.
21-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
21+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
2222
public enum GenerativeAISwift {
2323
/// String value of the SDK version
2424
public static let version = "0.5.4"
2525
/// The Google AI backend endpoint URL.
2626
static let baseURL = "https://generativelanguage.googleapis.com"
27-
}
27+
}

Sources/GoogleAI/GenerativeModel.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public final class GenerativeModel {
220220
/// for conforming types).
221221
/// - Returns: A stream wrapping content generated by the model or a ``GenerateContentError``
222222
/// error if an error occurred.
223-
@available(macOS 12.0, *)
223+
@available(macOS 12.0, watchOS 8.0, *)
224224
public func generateContentStream(_ parts: any ThrowingPartsRepresentable...)
225225
-> AsyncThrowingStream<GenerateContentResponse, Error> {
226226
return try generateContentStream([ModelContent(parts: parts)])
@@ -231,7 +231,7 @@ public final class GenerativeModel {
231231
/// - Parameter content: The input(s) given to the model as a prompt.
232232
/// - Returns: A stream wrapping content generated by the model or a ``GenerateContentError``
233233
/// error if an error occurred.
234-
@available(macOS 12.0, *)
234+
@available(macOS 12.0, watchOS 8.0, *)
235235
public func generateContentStream(_ content: @autoclosure () throws -> [ModelContent])
236236
-> AsyncThrowingStream<GenerateContentResponse, Error> {
237237
let evaluatedContent: [ModelContent]
@@ -370,7 +370,7 @@ public final class GenerativeModel {
370370
}
371371

372372
/// An error thrown in `GenerativeModel.countTokens(_:)`.
373-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
373+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
374374
public enum CountTokensError: Error {
375375
case internalError(underlying: Error)
376-
}
376+
}

Sources/GoogleAI/JSONValue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ extension JSONValue: Encodable {
9393
}
9494
}
9595

96-
extension JSONValue: Equatable {}
96+
extension JSONValue: Equatable {}

Sources/GoogleAI/Logging.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ struct Logging {
5353
return Logger(.disabled)
5454
}
5555
}()
56-
}
56+
}

Sources/GoogleAI/ModelContent.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Foundation
1717
/// A type describing data in media formats interpretable by an AI model. Each generative AI
1818
/// request or response contains an `Array` of ``ModelContent``s, and each ``ModelContent`` value
1919
/// may comprise multiple heterogeneous ``ModelContent/Part``s.
20-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
20+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
2121
public struct ModelContent: Equatable {
2222
/// A discrete piece of data in a media format intepretable by an AI model. Within a single value
2323
/// of ``Part``, different data types may not mix.
@@ -118,10 +118,10 @@ public struct ModelContent: Equatable {
118118

119119
// MARK: Codable Conformances
120120

121-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
121+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
122122
extension ModelContent: Codable {}
123123

124-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 7.0, *)
124+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
125125
extension ModelContent.Part: Codable {
126126
enum CodingKeys: String, CodingKey {
127127
case text
@@ -188,4 +188,4 @@ extension ModelContent.Part: Codable {
188188
))
189189
}
190190
}
191-
}
191+
}

0 commit comments

Comments
 (0)