@@ -103,8 +103,8 @@ public static ModelContent FileData(string mimeType, System.Uri uri) {
103
103
/// `FunctionResponsePart` containing the given name and args.
104
104
/// </summary>
105
105
public static ModelContent FunctionResponse (
106
- string name , IDictionary < string , object > response ) {
107
- return new ModelContent ( new FunctionResponsePart ( name , response ) ) ;
106
+ string name , IDictionary < string , object > response , string id = null ) {
107
+ return new ModelContent ( new FunctionResponsePart ( name , response , id ) ) ;
108
108
}
109
109
110
110
// TODO: Possibly more, like Multi, Model, FunctionResponses, System (only on Dart?)
@@ -236,22 +236,31 @@ Dictionary<string, object> Part.ToJson() {
236
236
/// The function parameters and values, matching the registered schema.
237
237
/// </summary>
238
238
public IReadOnlyDictionary < string , object > Args { get ; }
239
+ /// <summary>
240
+ /// An identifier that should be passed along in the FunctionResponsePart.
241
+ /// </summary>
242
+ public string Id { get ; }
239
243
240
244
/// <summary>
241
245
/// Intended for internal use only.
242
246
/// </summary>
243
- internal FunctionCallPart ( string name , IDictionary < string , object > args ) {
247
+ internal FunctionCallPart ( string name , IDictionary < string , object > args , string id ) {
244
248
Name = name ;
245
249
Args = new Dictionary < string , object > ( args ) ;
250
+ Id = id ;
246
251
}
247
252
248
253
Dictionary < string , object > Part . ToJson ( ) {
254
+ var jsonDict = new Dictionary < string , object > ( ) {
255
+ { "name" , Name } ,
256
+ { "args" , Args }
257
+ } ;
258
+ if ( ! string . IsNullOrEmpty ( Id ) ) {
259
+ jsonDict [ "id" ] = Id ;
260
+ }
261
+
249
262
return new Dictionary < string , object > ( ) {
250
- { "functionCall" , new Dictionary < string , object > ( ) {
251
- { "name" , Name } ,
252
- { "args" , Args }
253
- }
254
- }
263
+ { "functionCall" , jsonDict }
255
264
} ;
256
265
}
257
266
}
@@ -272,24 +281,33 @@ Dictionary<string, object> Part.ToJson() {
272
281
/// The function's response or return value.
273
282
/// </summary>
274
283
public IReadOnlyDictionary < string , object > Response { get ; }
284
+ /// <summary>
285
+ /// The id from the FunctionCallPart this is in response to.
286
+ /// </summary>
287
+ public string Id { get ; }
275
288
276
289
/// <summary>
277
290
/// Constructs a new `FunctionResponsePart`.
278
291
/// </summary>
279
292
/// <param name="name">The name of the function that was called.</param>
280
293
/// <param name="response">The function's response.</param>
281
- public FunctionResponsePart ( string name , IDictionary < string , object > response ) {
294
+ /// <param name="id">The id from the FunctionCallPart this is in response to.</param>
295
+ public FunctionResponsePart ( string name , IDictionary < string , object > response , string id = null ) {
282
296
Name = name ;
283
297
Response = new Dictionary < string , object > ( response ) ;
298
+ Id = id ;
284
299
}
285
300
286
301
Dictionary < string , object > Part . ToJson ( ) {
302
+ var result = new Dictionary < string , object > ( ) {
303
+ { "name" , Name } ,
304
+ { "response" , Response }
305
+ } ;
306
+ if ( ! string . IsNullOrEmpty ( Id ) ) {
307
+ result [ "id" ] = Id ;
308
+ }
287
309
return new Dictionary < string , object > ( ) {
288
- { "functionResponse" , new Dictionary < string , object > ( ) {
289
- { "name" , Name } ,
290
- { "response" , Response }
291
- }
292
- }
310
+ { "functionResponse" , result }
293
311
} ;
294
312
}
295
313
}
@@ -350,7 +368,8 @@ internal static class ModelContentJsonParsers {
350
368
internal static ModelContent . FunctionCallPart FunctionCallPartFromJson ( Dictionary < string , object > jsonDict ) {
351
369
return new ModelContent . FunctionCallPart (
352
370
jsonDict . ParseValue < string > ( "name" , JsonParseOptions . ThrowEverything ) ,
353
- jsonDict . ParseValue < Dictionary < string , object > > ( "args" , JsonParseOptions . ThrowEverything ) ) ;
371
+ jsonDict . ParseValue < Dictionary < string , object > > ( "args" , JsonParseOptions . ThrowEverything ) ,
372
+ jsonDict . ParseValue < string > ( "id" ) ) ;
354
373
}
355
374
}
356
375
0 commit comments