Skip to content

Commit 5822291

Browse files
authored
[Vertex AI] Refactor Schema declarations (#13616)
1 parent 5fe65b9 commit 5822291

File tree

5 files changed

+345
-45
lines changed

5 files changed

+345
-45
lines changed

FirebaseVertexAI/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
renamed to `inlineData`; no functionality changes. (#13700)
1212
- [changed] **Breaking Change**: The property `citationSources` of
1313
`CitationMetadata` has been renamed to `citations`. (#13702)
14+
- [changed] **Breaking Change**: The constructor for `Schema` is now deprecated;
15+
use the new static methods `Schema.string(...)`, `Schema.object(...)`, etc.,
16+
instead. (#13616)
17+
- [changed] **Breaking Change**: The constructor for `FunctionDeclaration` now
18+
accepts an array of *optional* parameters instead of a list of *required*
19+
parameters; if a parameter is not listed as optional it is assumed to be
20+
required. (#13616)
1421

1522
# 11.3.0
1623
- [added] Added `Decodable` conformance for `FunctionResponse`. (#13606)

FirebaseVertexAI/Sample/FunctionCallingSample/ViewModels/FunctionCallingViewModel.swift

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,15 @@ class FunctionCallingViewModel: ObservableObject {
4545
name: "get_exchange_rate",
4646
description: "Get the exchange rate for currencies between countries",
4747
parameters: [
48-
"currency_from": Schema(
49-
type: .string,
50-
format: "enum",
51-
description: "The currency to convert from in ISO 4217 format",
52-
enumValues: ["USD", "EUR", "JPY", "GBP", "AUD", "CAD"]
48+
"currency_from": .enumeration(
49+
values: ["USD", "EUR", "JPY", "GBP", "AUD", "CAD"],
50+
description: "The currency to convert from in ISO 4217 format"
5351
),
54-
"currency_to": Schema(
55-
type: .string,
56-
format: "enum",
57-
description: "The currency to convert to in ISO 4217 format",
58-
enumValues: ["USD", "EUR", "JPY", "GBP", "AUD", "CAD"]
52+
"currency_to": .enumeration(
53+
values: ["USD", "EUR", "JPY", "GBP", "AUD", "CAD"],
54+
description: "The currency to convert to in ISO 4217 format"
5955
),
60-
],
61-
requiredParameters: ["currency_from", "currency_to"]
56+
]
6257
),
6358
])]
6459
)

FirebaseVertexAI/Sources/FunctionCalling.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,15 @@ public struct FunctionDeclaration {
4343
/// - name: The name of the function; must be a-z, A-Z, 0-9, or contain underscores and dashes,
4444
/// with a maximum length of 63.
4545
/// - description: A brief description of the function.
46-
/// - parameters: Describes the parameters to this function; the keys are parameter names and
47-
/// the values are ``Schema`` objects describing them.
48-
/// - requiredParameters: A list of required parameters by name.
49-
public init(name: String, description: String, parameters: [String: Schema]?,
50-
requiredParameters: [String]? = nil) {
46+
/// - parameters: Describes the parameters to this function.
47+
public init(name: String, description: String, parameters: [String: Schema],
48+
optionalParameters: [String] = []) {
5149
self.name = name
5250
self.description = description
53-
self.parameters = Schema(
54-
type: .object,
51+
self.parameters = Schema.object(
5552
properties: parameters,
56-
requiredProperties: requiredParameters
53+
optionalProperties: optionalParameters,
54+
nullable: false
5755
)
5856
}
5957
}

0 commit comments

Comments
 (0)