Skip to content

Commit 12f9f27

Browse files
committed
Temporarily add support for function behavior
1 parent b469e9c commit 12f9f27

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

FirebaseAI/Sources/Tool.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public struct FunctionDeclaration: Sendable {
2929
/// Describes the parameters to this function; must be of type `DataType.object`.
3030
let parameters: Schema?
3131

32+
// TODO: remove (added for testing)
33+
let behavior: FunctionBehavior?
34+
3235
/// Constructs a new `FunctionDeclaration`.
3336
///
3437
/// - Parameters:
@@ -40,8 +43,21 @@ public struct FunctionDeclaration: Sendable {
4043
/// calls; by default, all parameters are considered required.
4144
public init(name: String, description: String, parameters: [String: Schema],
4245
optionalParameters: [String] = []) {
46+
self.init(
47+
name: name,
48+
description: description,
49+
parameters: parameters,
50+
optionalParameters: optionalParameters,
51+
functionBehavior: nil
52+
)
53+
}
54+
55+
// TODO: remove (added for testing)
56+
public init(name: String, description: String, parameters: [String: Schema],
57+
optionalParameters: [String] = [], functionBehavior: FunctionBehavior? = nil) {
4358
self.name = name
4459
self.description = description
60+
behavior = functionBehavior
4561
self.parameters = Schema.object(
4662
properties: parameters,
4763
optionalProperties: optionalParameters,
@@ -50,6 +66,12 @@ public struct FunctionDeclaration: Sendable {
5066
}
5167
}
5268

69+
// TODO: remove (added for testing)
70+
public enum FunctionBehavior: String, Sendable, Encodable {
71+
case blocking = "BLOCKING"
72+
case nonBlocking = "NON_BLOCKING"
73+
}
74+
5375
/// A tool that allows the generative model to connect to Google Search to access and incorporate
5476
/// up-to-date information from the web into its responses.
5577
///
@@ -200,13 +222,15 @@ extension FunctionDeclaration: Encodable {
200222
case name
201223
case description
202224
case parameters
225+
case behavior // TODO: remove (added for testing)
203226
}
204227

205228
public func encode(to encoder: Encoder) throws {
206229
var container = encoder.container(keyedBy: CodingKeys.self)
207230
try container.encode(name, forKey: .name)
208231
try container.encode(description, forKey: .description)
209232
try container.encode(parameters, forKey: .parameters)
233+
try container.encode(behavior, forKey: .behavior) // TODO: remove (added for testing)
210234
}
211235
}
212236

0 commit comments

Comments
 (0)