Skip to content

Commit d5e375f

Browse files
committed
Add missing ID field
1 parent 9b83676 commit d5e375f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

FirebaseAI/Sources/Types/Internal/InternalPart.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ struct FileData: Codable, Equatable, Sendable {
4545
struct FunctionCall: Equatable, Sendable {
4646
let name: String
4747
let args: JSONObject
48+
let id: String?
4849

49-
init(name: String, args: JSONObject) {
50+
init(name: String, args: JSONObject, id: String?) {
5051
self.name = name
5152
self.args = args
53+
self.id = id
5254
}
5355
}
5456

@@ -137,6 +139,7 @@ extension FunctionCall: Codable {
137139
} else {
138140
args = JSONObject()
139141
}
142+
id = try container.decode(String.self, forKey: .id)
140143
}
141144
}
142145

FirebaseAI/Sources/Types/Public/Part.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public struct FunctionCallPart: Part {
147147

148148
public var isThought: Bool { _isThought ?? false }
149149

150+
public var id: String?
150151
/// Constructs a new function call part.
151152
///
152153
/// > Note: A `FunctionCallPart` is typically received from the model, rather than created
@@ -156,7 +157,21 @@ public struct FunctionCallPart: Part {
156157
/// - name: The name of the function to call.
157158
/// - args: The function parameters and values.
158159
public init(name: String, args: JSONObject) {
159-
self.init(FunctionCall(name: name, args: args), isThought: nil, thoughtSignature: nil)
160+
self.init(FunctionCall(name: name, args: args, id: nil), isThought: nil, thoughtSignature: nil)
161+
}
162+
163+
/// Constructs a new function call part.
164+
///
165+
/// > Note: A `FunctionCallPart` is typically received from the model, rather than created
166+
/// manually.
167+
///
168+
/// - Parameters:
169+
/// - name: The name of the function to call.
170+
/// - args: The function parameters and values.
171+
/// - id: Unique id of the function call. If present, the returned ``FunctionResponsePart``
172+
/// should have a matching `id` field.
173+
public init(name: String, args: JSONObject, id: String? = nil) {
174+
self.init(FunctionCall(name: name, args: args, id: id), isThought: nil, thoughtSignature: nil)
160175
}
161176

162177
init(_ functionCall: FunctionCall, isThought: Bool? = nil, thoughtSignature: String? = nil) {

0 commit comments

Comments
 (0)