Skip to content

Commit 584b1e9

Browse files
authored
Remove public Codable (Decodable and/or Encodable) conformance (#142)
1 parent d08fb28 commit 584b1e9

File tree

6 files changed

+302
-254
lines changed

6 files changed

+302
-254
lines changed

Sources/GoogleAI/CountTokensRequest.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ struct CountTokensRequest {
2121
let options: RequestOptions
2222
}
2323

24-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
25-
extension CountTokensRequest: Encodable {
26-
enum CodingKeys: CodingKey {
27-
case contents
28-
}
29-
}
30-
3124
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
3225
extension CountTokensRequest: GenerativeAIRequest {
3326
typealias Response = CountTokensResponse
@@ -39,7 +32,19 @@ extension CountTokensRequest: GenerativeAIRequest {
3932

4033
/// The model's response to a count tokens request.
4134
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
42-
public struct CountTokensResponse: Decodable {
35+
public struct CountTokensResponse {
4336
/// The total number of tokens in the input given to the model as a prompt.
4437
public let totalTokens: Int
4538
}
39+
40+
// MARK: - Codable Conformances
41+
42+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
43+
extension CountTokensRequest: Encodable {
44+
enum CodingKeys: CodingKey {
45+
case contents
46+
}
47+
}
48+
49+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
50+
extension CountTokensResponse: Decodable {}

Sources/GoogleAI/FunctionCalling.swift

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Foundation
1616

1717
/// A predicted function call returned from the model.
18-
public struct FunctionCall: Equatable, Encodable {
18+
public struct FunctionCall: Equatable {
1919
/// The name of the function to call.
2020
public let name: String
2121

@@ -27,7 +27,7 @@ public struct FunctionCall: Equatable, Encodable {
2727
///
2828
/// These types can be objects, but also primitives and arrays. Represents a select subset of an
2929
/// [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema).
30-
public class Schema: Encodable {
30+
public class Schema {
3131
/// The data type.
3232
let type: DataType
3333

@@ -98,7 +98,7 @@ public class Schema: Encodable {
9898
/// A data type.
9999
///
100100
/// Contains the set of OpenAPI [data types](https://spec.openapis.org/oas/v3.0.3#data-types).
101-
public enum DataType: String, Encodable {
101+
public enum DataType: String {
102102
/// A `String` type.
103103
case string = "STRING"
104104

@@ -157,7 +157,7 @@ public struct FunctionDeclaration {
157157
///
158158
/// A `Tool` is a piece of code that enables the system to interact with external systems to
159159
/// perform an action, or set of actions, outside of knowledge and scope of the model.
160-
public struct Tool: Encodable {
160+
public struct Tool {
161161
/// A list of `FunctionDeclarations` available to the model.
162162
let functionDeclarations: [FunctionDeclaration]?
163163

@@ -178,10 +178,10 @@ public struct Tool: Encodable {
178178
}
179179

180180
/// Configuration for specifying function calling behavior.
181-
public struct FunctionCallingConfig: Encodable {
181+
public struct FunctionCallingConfig {
182182
/// Defines the execution behavior for function calling by defining the
183183
/// execution mode.
184-
public enum Mode: String, Encodable {
184+
public enum Mode: String {
185185
/// The default behavior for function calling. The model calls functions to answer queries at
186186
/// its discretion.
187187
case auto = "AUTO"
@@ -213,8 +213,7 @@ public struct FunctionCallingConfig: Encodable {
213213
}
214214

215215
/// Tool configuration for any `Tool` specified in the request.
216-
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
217-
public struct ToolConfig: Encodable {
216+
public struct ToolConfig {
218217
let functionCallingConfig: FunctionCallingConfig?
219218

220219
public init(functionCallingConfig: FunctionCallingConfig? = nil) {
@@ -227,7 +226,7 @@ public struct ToolConfig: Encodable {
227226
/// Contains a string representing the `FunctionDeclaration.name` and a structured JSON object
228227
/// containing any output from the function is used as context to the model. This should contain the
229228
/// result of a ``FunctionCall`` made based on model prediction.
230-
public struct FunctionResponse: Equatable, Encodable {
229+
public struct FunctionResponse: Equatable {
231230
/// The name of the function that was called.
232231
let name: String
233232

@@ -264,6 +263,8 @@ extension FunctionCall: Decodable {
264263
}
265264
}
266265

266+
extension FunctionCall: Encodable {}
267+
267268
extension FunctionDeclaration: Encodable {
268269
enum CodingKeys: String, CodingKey {
269270
case name
@@ -278,3 +279,17 @@ extension FunctionDeclaration: Encodable {
278279
try container.encode(parameters, forKey: .parameters)
279280
}
280281
}
282+
283+
extension Schema: Encodable {}
284+
285+
extension DataType: Encodable {}
286+
287+
extension Tool: Encodable {}
288+
289+
extension FunctionCallingConfig: Encodable {}
290+
291+
extension FunctionCallingConfig.Mode: Encodable {}
292+
293+
extension ToolConfig: Encodable {}
294+
295+
extension FunctionResponse: Encodable {}

0 commit comments

Comments
 (0)