17
17
18
18
import {
19
19
aggregateResponses ,
20
- deleteEmptyTextParts ,
21
20
getResponseStream ,
22
21
processStream
23
22
} from './stream-reader' ;
@@ -34,7 +33,6 @@ import {
34
33
GenerateContentResponse ,
35
34
HarmCategory ,
36
35
HarmProbability ,
37
- Part ,
38
36
SafetyRating
39
37
} from '../types' ;
40
38
@@ -228,6 +226,7 @@ describe('processStream', () => {
228
226
) ;
229
227
const result = processStream ( fakeResponse as Response ) ;
230
228
const aggregatedResponse = await result . response ;
229
+ console . log ( aggregatedResponse . candidates ?. [ 0 ] . content . parts ) ;
231
230
expect ( aggregatedResponse . text ( ) ) . to . equal ( '1' ) ;
232
231
expect ( aggregatedResponse . candidates ?. length ) . to . equal ( 1 ) ;
233
232
expect ( aggregatedResponse . candidates ?. [ 0 ] . content . parts . length ) . to . equal ( 1 ) ;
@@ -423,104 +422,3 @@ describe('aggregateResponses', () => {
423
422
} ) ;
424
423
} ) ;
425
424
} ) ;
426
-
427
- describe ( 'deleteEmptyTextParts' , ( ) => {
428
- it ( 'removes empty text parts from a single candidate' , ( ) => {
429
- const parts : Part [ ] = [
430
- {
431
- text : ''
432
- } ,
433
- {
434
- text : 'foo'
435
- }
436
- ] ;
437
- const generateContentResponse : GenerateContentResponse = {
438
- candidates : [
439
- {
440
- index : 0 ,
441
- content : {
442
- role : 'model' ,
443
- parts
444
- }
445
- }
446
- ]
447
- } ;
448
-
449
- deleteEmptyTextParts ( generateContentResponse ) ;
450
- expect ( generateContentResponse . candidates ?. [ 0 ] . content . parts ) . to . deep . equal (
451
- [
452
- {
453
- text : 'foo'
454
- }
455
- ]
456
- ) ;
457
- } ) ;
458
- it ( 'removes empty text parts from all candidates' , ( ) => {
459
- const parts : Part [ ] = [
460
- {
461
- text : ''
462
- } ,
463
- {
464
- text : 'foo'
465
- }
466
- ] ;
467
- const generateContentResponse : GenerateContentResponse = {
468
- candidates : [
469
- {
470
- index : 0 ,
471
- content : {
472
- role : 'model' ,
473
- parts
474
- }
475
- } ,
476
- {
477
- index : 1 ,
478
- content : {
479
- role : 'model' ,
480
- parts
481
- }
482
- }
483
- ]
484
- } ;
485
-
486
- deleteEmptyTextParts ( generateContentResponse ) ;
487
- expect ( generateContentResponse . candidates ?. [ 0 ] . content . parts ) . to . deep . equal (
488
- [
489
- {
490
- text : 'foo'
491
- }
492
- ]
493
- ) ;
494
- expect ( generateContentResponse . candidates ?. [ 1 ] . content . parts ) . to . deep . equal (
495
- [
496
- {
497
- text : 'foo'
498
- }
499
- ]
500
- ) ;
501
- } ) ;
502
- it ( 'does not remove candidate even if all parts are removed' , ( ) => {
503
- const parts : Part [ ] = [
504
- {
505
- text : ''
506
- }
507
- ] ;
508
- const generateContentResponse : GenerateContentResponse = {
509
- candidates : [
510
- {
511
- index : 0 ,
512
- content : {
513
- role : 'model' ,
514
- parts
515
- }
516
- }
517
- ]
518
- } ;
519
-
520
- deleteEmptyTextParts ( generateContentResponse ) ;
521
- expect ( generateContentResponse . candidates ?. length ) . to . equal ( 1 ) ;
522
- expect ( generateContentResponse . candidates ?. [ 0 ] . content . parts ) . to . deep . equal (
523
- [ ]
524
- ) ;
525
- } ) ;
526
- } ) ;
0 commit comments