Skip to content

Commit

Permalink
Remove public Codable (Decodable and/or Encodable) conformance (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard authored Apr 19, 2024
1 parent d08fb28 commit 584b1e9
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 254 deletions.
21 changes: 13 additions & 8 deletions Sources/GoogleAI/CountTokensRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ struct CountTokensRequest {
let options: RequestOptions
}

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

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
extension CountTokensRequest: GenerativeAIRequest {
typealias Response = CountTokensResponse
Expand All @@ -39,7 +32,19 @@ extension CountTokensRequest: GenerativeAIRequest {

/// The model's response to a count tokens request.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
public struct CountTokensResponse: Decodable {
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, *)
extension CountTokensRequest: Encodable {
enum CodingKeys: CodingKey {
case contents
}
}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
extension CountTokensResponse: Decodable {}
33 changes: 24 additions & 9 deletions Sources/GoogleAI/FunctionCalling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import Foundation

/// A predicted function call returned from the model.
public struct FunctionCall: Equatable, Encodable {
public struct FunctionCall: Equatable {
/// The name of the function to call.
public let name: String

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

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

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

Expand All @@ -178,10 +178,10 @@ public struct Tool: Encodable {
}

/// Configuration for specifying function calling behavior.
public struct FunctionCallingConfig: Encodable {
public struct FunctionCallingConfig {
/// Defines the execution behavior for function calling by defining the
/// execution mode.
public enum Mode: String, Encodable {
public enum Mode: String {
/// The default behavior for function calling. The model calls functions to answer queries at
/// its discretion.
case auto = "AUTO"
Expand Down Expand Up @@ -213,8 +213,7 @@ public struct FunctionCallingConfig: Encodable {
}

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

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

Expand Down Expand Up @@ -264,6 +263,8 @@ extension FunctionCall: Decodable {
}
}

extension FunctionCall: Encodable {}

extension FunctionDeclaration: Encodable {
enum CodingKeys: String, CodingKey {
case name
Expand All @@ -278,3 +279,17 @@ extension FunctionDeclaration: Encodable {
try container.encode(parameters, forKey: .parameters)
}
}

extension Schema: Encodable {}

extension DataType: Encodable {}

extension Tool: Encodable {}

extension FunctionCallingConfig: Encodable {}

extension FunctionCallingConfig.Mode: Encodable {}

extension ToolConfig: Encodable {}

extension FunctionResponse: Encodable {}
Loading

0 comments on commit 584b1e9

Please sign in to comment.