Skip to content

Commit 6ddd42b

Browse files
authored
[Vertex AI] Move Schema and DataType to separate file (#13509)
1 parent 9118aca commit 6ddd42b

File tree

2 files changed

+116
-99
lines changed

2 files changed

+116
-99
lines changed

FirebaseVertexAI/Sources/FunctionCalling.swift

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -23,90 +23,6 @@ public struct FunctionCall: Equatable {
2323
public let args: JSONObject
2424
}
2525

26-
/// A `Schema` object allows the definition of input and output data types.
27-
///
28-
/// These types can be objects, but also primitives and arrays. Represents a select subset of an
29-
/// [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema).
30-
public class Schema {
31-
/// The data type.
32-
let type: DataType
33-
34-
/// The format of the data.
35-
let format: String?
36-
37-
/// A brief description of the parameter.
38-
let description: String?
39-
40-
/// Indicates if the value may be null.
41-
let nullable: Bool?
42-
43-
/// Possible values of the element of type ``DataType/string`` with "enum" format.
44-
let enumValues: [String]?
45-
46-
/// Schema of the elements of type ``DataType/array``.
47-
let items: Schema?
48-
49-
/// Properties of type ``DataType/object``.
50-
let properties: [String: Schema]?
51-
52-
/// Required properties of type ``DataType/object``.
53-
let requiredProperties: [String]?
54-
55-
/// Constructs a new `Schema`.
56-
///
57-
/// - Parameters:
58-
/// - type: The data type.
59-
/// - format: The format of the data; used only for primitive datatypes.
60-
/// Supported formats:
61-
/// - ``DataType/integer``: int32, int64
62-
/// - ``DataType/number``: float, double
63-
/// - ``DataType/string``: enum
64-
/// - description: A brief description of the parameter; may be formatted as Markdown.
65-
/// - nullable: Indicates if the value may be null.
66-
/// - enumValues: Possible values of the element of type ``DataType/string`` with "enum" format.
67-
/// For example, an enum `Direction` may be defined as `["EAST", NORTH", "SOUTH", "WEST"]`.
68-
/// - items: Schema of the elements of type ``DataType/array``.
69-
/// - properties: Properties of type ``DataType/object``.
70-
/// - requiredProperties: Required properties of type ``DataType/object``.
71-
public init(type: DataType, format: String? = nil, description: String? = nil,
72-
nullable: Bool? = nil,
73-
enumValues: [String]? = nil, items: Schema? = nil,
74-
properties: [String: Schema]? = nil,
75-
requiredProperties: [String]? = nil) {
76-
self.type = type
77-
self.format = format
78-
self.description = description
79-
self.nullable = nullable
80-
self.enumValues = enumValues
81-
self.items = items
82-
self.properties = properties
83-
self.requiredProperties = requiredProperties
84-
}
85-
}
86-
87-
/// A data type.
88-
///
89-
/// Contains the set of OpenAPI [data types](https://spec.openapis.org/oas/v3.0.3#data-types).
90-
public enum DataType: String {
91-
/// A `String` type.
92-
case string = "STRING"
93-
94-
/// A floating-point number type.
95-
case number = "NUMBER"
96-
97-
/// An integer type.
98-
case integer = "INTEGER"
99-
100-
/// A boolean type.
101-
case boolean = "BOOLEAN"
102-
103-
/// An array type.
104-
case array = "ARRAY"
105-
106-
/// An object type.
107-
case object = "OBJECT"
108-
}
109-
11026
/// Structured representation of a function declaration.
11127
///
11228
/// This `FunctionDeclaration` is a representation of a block of code that can be used as a ``Tool``
@@ -269,21 +185,6 @@ extension FunctionDeclaration: Encodable {
269185
}
270186
}
271187

272-
extension Schema: Encodable {
273-
enum CodingKeys: String, CodingKey {
274-
case type
275-
case format
276-
case description
277-
case nullable
278-
case enumValues = "enum"
279-
case items
280-
case properties
281-
case requiredProperties = "required"
282-
}
283-
}
284-
285-
extension DataType: Encodable {}
286-
287188
extension Tool: Encodable {}
288189

289190
extension FunctionCallingConfig: Encodable {}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Foundation
16+
17+
/// A `Schema` object allows the definition of input and output data types.
18+
///
19+
/// These types can be objects, but also primitives and arrays. Represents a select subset of an
20+
/// [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema).
21+
public class Schema {
22+
/// The data type.
23+
let type: DataType
24+
25+
/// The format of the data.
26+
let format: String?
27+
28+
/// A brief description of the parameter.
29+
let description: String?
30+
31+
/// Indicates if the value may be null.
32+
let nullable: Bool?
33+
34+
/// Possible values of the element of type ``DataType/string`` with "enum" format.
35+
let enumValues: [String]?
36+
37+
/// Schema of the elements of type ``DataType/array``.
38+
let items: Schema?
39+
40+
/// Properties of type ``DataType/object``.
41+
let properties: [String: Schema]?
42+
43+
/// Required properties of type ``DataType/object``.
44+
let requiredProperties: [String]?
45+
46+
/// Constructs a new `Schema`.
47+
///
48+
/// - Parameters:
49+
/// - type: The data type.
50+
/// - format: The format of the data; used only for primitive datatypes.
51+
/// Supported formats:
52+
/// - ``DataType/integer``: int32, int64
53+
/// - ``DataType/number``: float, double
54+
/// - ``DataType/string``: enum
55+
/// - description: A brief description of the parameter; may be formatted as Markdown.
56+
/// - nullable: Indicates if the value may be null.
57+
/// - enumValues: Possible values of the element of type ``DataType/string`` with "enum" format.
58+
/// For example, an enum `Direction` may be defined as `["EAST", NORTH", "SOUTH", "WEST"]`.
59+
/// - items: Schema of the elements of type ``DataType/array``.
60+
/// - properties: Properties of type ``DataType/object``.
61+
/// - requiredProperties: Required properties of type ``DataType/object``.
62+
public init(type: DataType, format: String? = nil, description: String? = nil,
63+
nullable: Bool? = nil,
64+
enumValues: [String]? = nil, items: Schema? = nil,
65+
properties: [String: Schema]? = nil,
66+
requiredProperties: [String]? = nil) {
67+
self.type = type
68+
self.format = format
69+
self.description = description
70+
self.nullable = nullable
71+
self.enumValues = enumValues
72+
self.items = items
73+
self.properties = properties
74+
self.requiredProperties = requiredProperties
75+
}
76+
}
77+
78+
/// A data type.
79+
///
80+
/// Contains the set of OpenAPI [data types](https://spec.openapis.org/oas/v3.0.3#data-types).
81+
public enum DataType: String {
82+
/// A `String` type.
83+
case string = "STRING"
84+
85+
/// A floating-point number type.
86+
case number = "NUMBER"
87+
88+
/// An integer type.
89+
case integer = "INTEGER"
90+
91+
/// A boolean type.
92+
case boolean = "BOOLEAN"
93+
94+
/// An array type.
95+
case array = "ARRAY"
96+
97+
/// An object type.
98+
case object = "OBJECT"
99+
}
100+
101+
// MARK: - Codable Conformance
102+
103+
extension Schema: Encodable {
104+
enum CodingKeys: String, CodingKey {
105+
case type
106+
case format
107+
case description
108+
case nullable
109+
case enumValues = "enum"
110+
case items
111+
case properties
112+
case requiredProperties = "required"
113+
}
114+
}
115+
116+
extension DataType: Encodable {}

0 commit comments

Comments
 (0)