@@ -231,8 +231,8 @@ describe('parseComplexResponse function', () => {
231
231
// Execute the parser function
232
232
const result = await parseComplexResponse ( {
233
233
reader : createTestReader ( [
234
- '0:"Sample text message."\n' ,
235
234
'8:[{"key":"value"}, 2]\n' ,
235
+ '0:"Sample text message."\n' ,
236
236
] ) ,
237
237
abortControllerRef : { current : new AbortController ( ) } ,
238
238
update : mockUpdate ,
@@ -243,9 +243,7 @@ describe('parseComplexResponse function', () => {
243
243
// check the mockUpdate call:
244
244
expect ( mockUpdate ) . toHaveBeenCalledTimes ( 2 ) ;
245
245
246
- expect ( mockUpdate . mock . calls [ 0 ] [ 0 ] ) . toEqual ( [
247
- assistantTextMessage ( 'Sample text message.' ) ,
248
- ] ) ;
246
+ expect ( mockUpdate . mock . calls [ 0 ] [ 0 ] ) . toEqual ( [ ] ) ;
249
247
250
248
expect ( mockUpdate . mock . calls [ 1 ] [ 0 ] ) . toEqual ( [
251
249
{
@@ -265,4 +263,91 @@ describe('parseComplexResponse function', () => {
265
263
data : [ ] ,
266
264
} ) ;
267
265
} ) ;
266
+
267
+ it ( 'should parse a combination of a function_call and message annotations' , async ( ) => {
268
+ const mockUpdate = vi . fn ( ) ;
269
+
270
+ // Execute the parser function
271
+ const result = await parseComplexResponse ( {
272
+ reader : createTestReader ( [
273
+ '1:{"function_call":{"name":"get_current_weather","arguments":"{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}\n' ,
274
+ '8:[{"key":"value"}, 2]\n' ,
275
+ '8:[null,false,"text"]\n' ,
276
+ ] ) ,
277
+ abortControllerRef : { current : new AbortController ( ) } ,
278
+ update : mockUpdate ,
279
+ generateId : ( ) => 'test-id' ,
280
+ getCurrentDate : ( ) => new Date ( 0 ) ,
281
+ } ) ;
282
+
283
+ // check the mockUpdate call:
284
+ expect ( mockUpdate ) . toHaveBeenCalledTimes ( 3 ) ;
285
+
286
+ expect ( mockUpdate . mock . calls [ 0 ] [ 0 ] ) . toEqual ( [
287
+ {
288
+ content : '' ,
289
+ createdAt : new Date ( 0 ) ,
290
+ id : 'test-id' ,
291
+ role : 'assistant' ,
292
+ function_call : {
293
+ name : 'get_current_weather' ,
294
+ arguments :
295
+ '{\n"location": "Charlottesville, Virginia",\n"format": "celsius"\n}' ,
296
+ } ,
297
+ name : 'get_current_weather' ,
298
+ } ,
299
+ ] ) ;
300
+
301
+ expect ( mockUpdate . mock . calls [ 1 ] [ 0 ] ) . toEqual ( [
302
+ {
303
+ content : '' ,
304
+ createdAt : new Date ( 0 ) ,
305
+ id : 'test-id' ,
306
+ role : 'assistant' ,
307
+ function_call : {
308
+ name : 'get_current_weather' ,
309
+ arguments :
310
+ '{\n"location": "Charlottesville, Virginia",\n"format": "celsius"\n}' ,
311
+ } ,
312
+ name : 'get_current_weather' ,
313
+ annotations : [ { key : 'value' } , 2 ] ,
314
+ } ,
315
+ ] ) ;
316
+
317
+ expect ( mockUpdate . mock . calls [ 2 ] [ 0 ] ) . toEqual ( [
318
+ {
319
+ content : '' ,
320
+ createdAt : new Date ( 0 ) ,
321
+ id : 'test-id' ,
322
+ role : 'assistant' ,
323
+ function_call : {
324
+ name : 'get_current_weather' ,
325
+ arguments :
326
+ '{\n"location": "Charlottesville, Virginia",\n"format": "celsius"\n}' ,
327
+ } ,
328
+ name : 'get_current_weather' ,
329
+ annotations : [ { key : 'value' } , 2 , null , false , 'text' ] ,
330
+ } ,
331
+ ] ) ;
332
+
333
+ // check the result
334
+ expect ( result ) . toEqual ( {
335
+ messages : [
336
+ {
337
+ content : '' ,
338
+ createdAt : new Date ( 0 ) ,
339
+ id : 'test-id' ,
340
+ role : 'assistant' ,
341
+ function_call : {
342
+ name : 'get_current_weather' ,
343
+ arguments :
344
+ '{\n"location": "Charlottesville, Virginia",\n"format": "celsius"\n}' ,
345
+ } ,
346
+ name : 'get_current_weather' ,
347
+ annotations : [ { key : 'value' } , 2 , null , false , 'text' ] ,
348
+ } ,
349
+ ] ,
350
+ data : [ ] ,
351
+ } ) ;
352
+ } ) ;
268
353
} ) ;
0 commit comments