Skip to content

Commit

Permalink
[Vertex AI] Refactor Schema declarations (#13616)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard authored Sep 25, 2024
1 parent 5fe65b9 commit 5822291
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 45 deletions.
7 changes: 7 additions & 0 deletions FirebaseVertexAI/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
renamed to `inlineData`; no functionality changes. (#13700)
- [changed] **Breaking Change**: The property `citationSources` of
`CitationMetadata` has been renamed to `citations`. (#13702)
- [changed] **Breaking Change**: The constructor for `Schema` is now deprecated;
use the new static methods `Schema.string(...)`, `Schema.object(...)`, etc.,
instead. (#13616)
- [changed] **Breaking Change**: The constructor for `FunctionDeclaration` now
accepts an array of *optional* parameters instead of a list of *required*
parameters; if a parameter is not listed as optional it is assumed to be
required. (#13616)

# 11.3.0
- [added] Added `Decodable` conformance for `FunctionResponse`. (#13606)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,15 @@ class FunctionCallingViewModel: ObservableObject {
name: "get_exchange_rate",
description: "Get the exchange rate for currencies between countries",
parameters: [
"currency_from": Schema(
type: .string,
format: "enum",
description: "The currency to convert from in ISO 4217 format",
enumValues: ["USD", "EUR", "JPY", "GBP", "AUD", "CAD"]
"currency_from": .enumeration(
values: ["USD", "EUR", "JPY", "GBP", "AUD", "CAD"],
description: "The currency to convert from in ISO 4217 format"
),
"currency_to": Schema(
type: .string,
format: "enum",
description: "The currency to convert to in ISO 4217 format",
enumValues: ["USD", "EUR", "JPY", "GBP", "AUD", "CAD"]
"currency_to": .enumeration(
values: ["USD", "EUR", "JPY", "GBP", "AUD", "CAD"],
description: "The currency to convert to in ISO 4217 format"
),
],
requiredParameters: ["currency_from", "currency_to"]
]
),
])]
)
Expand Down
14 changes: 6 additions & 8 deletions FirebaseVertexAI/Sources/FunctionCalling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,15 @@ public struct FunctionDeclaration {
/// - name: The name of the function; must be a-z, A-Z, 0-9, or contain underscores and dashes,
/// with a maximum length of 63.
/// - description: A brief description of the function.
/// - parameters: Describes the parameters to this function; the keys are parameter names and
/// the values are ``Schema`` objects describing them.
/// - requiredParameters: A list of required parameters by name.
public init(name: String, description: String, parameters: [String: Schema]?,
requiredParameters: [String]? = nil) {
/// - parameters: Describes the parameters to this function.
public init(name: String, description: String, parameters: [String: Schema],
optionalParameters: [String] = []) {
self.name = name
self.description = description
self.parameters = Schema(
type: .object,
self.parameters = Schema.object(
properties: parameters,
requiredProperties: requiredParameters
optionalProperties: optionalParameters,
nullable: false
)
}
}
Expand Down
Loading

0 comments on commit 5822291

Please sign in to comment.