@@ -136,6 +136,17 @@ describe('toGeminiMessages', () => {
136
136
] ,
137
137
} ,
138
138
} ,
139
+ {
140
+ should : 'should re-populate thoughtSignature from reasoning metadata' ,
141
+ inputMessage : {
142
+ role : 'model' ,
143
+ content : [ { reasoning : '' , metadata : { thoughtSignature : 'abc123' } } ] ,
144
+ } ,
145
+ expectedOutput : {
146
+ role : 'model' ,
147
+ parts : [ { thought : true , thoughtSignature : 'abc123' } ] ,
148
+ } ,
149
+ } ,
139
150
] ;
140
151
for ( const test of testCases ) {
141
152
it ( test . should , ( ) => {
@@ -365,6 +376,102 @@ describe('fromGeminiCandidate', () => {
365
376
} ,
366
377
} ,
367
378
} ,
379
+ {
380
+ should :
381
+ 'should transform gemini candidate to genkit candidate (thought parts) correctly' ,
382
+ geminiCandidate : {
383
+ content : {
384
+ role : 'model' ,
385
+ parts : [
386
+ {
387
+ thought : true ,
388
+ thoughtSignature : 'abc123' ,
389
+ } ,
390
+ {
391
+ thought : true ,
392
+ text : 'thought with text' ,
393
+ thoughtSignature : 'def456' ,
394
+ } ,
395
+ ] ,
396
+ } ,
397
+ finishReason : 'STOP' ,
398
+ safetyRatings : [
399
+ {
400
+ category : 'HARM_CATEGORY_HATE_SPEECH' ,
401
+ probability : 'NEGLIGIBLE' ,
402
+ probabilityScore : 0.11858909 ,
403
+ severity : 'HARM_SEVERITY_NEGLIGIBLE' ,
404
+ severityScore : 0.11456649 ,
405
+ } ,
406
+ {
407
+ category : 'HARM_CATEGORY_DANGEROUS_CONTENT' ,
408
+ probability : 'NEGLIGIBLE' ,
409
+ probabilityScore : 0.13857833 ,
410
+ severity : 'HARM_SEVERITY_NEGLIGIBLE' ,
411
+ severityScore : 0.11417085 ,
412
+ } ,
413
+ {
414
+ category : 'HARM_CATEGORY_HARASSMENT' ,
415
+ probability : 'NEGLIGIBLE' ,
416
+ probabilityScore : 0.28012377 ,
417
+ severity : 'HARM_SEVERITY_NEGLIGIBLE' ,
418
+ severityScore : 0.112405084 ,
419
+ } ,
420
+ {
421
+ category : 'HARM_CATEGORY_SEXUALLY_EXPLICIT' ,
422
+ probability : 'NEGLIGIBLE' ,
423
+ } ,
424
+ ] ,
425
+ } ,
426
+ expectedOutput : {
427
+ index : 0 ,
428
+ message : {
429
+ role : 'model' ,
430
+ content : [
431
+ {
432
+ reasoning : '' ,
433
+ metadata : { thoughtSignature : 'abc123' } ,
434
+ } ,
435
+ {
436
+ reasoning : 'thought with text' ,
437
+ metadata : { thoughtSignature : 'def456' } ,
438
+ } ,
439
+ ] ,
440
+ } ,
441
+ finishReason : 'stop' ,
442
+ finishMessage : undefined ,
443
+ custom : {
444
+ citationMetadata : undefined ,
445
+ safetyRatings : [
446
+ {
447
+ category : 'HARM_CATEGORY_HATE_SPEECH' ,
448
+ probability : 'NEGLIGIBLE' ,
449
+ probabilityScore : 0.11858909 ,
450
+ severity : 'HARM_SEVERITY_NEGLIGIBLE' ,
451
+ severityScore : 0.11456649 ,
452
+ } ,
453
+ {
454
+ category : 'HARM_CATEGORY_DANGEROUS_CONTENT' ,
455
+ probability : 'NEGLIGIBLE' ,
456
+ probabilityScore : 0.13857833 ,
457
+ severity : 'HARM_SEVERITY_NEGLIGIBLE' ,
458
+ severityScore : 0.11417085 ,
459
+ } ,
460
+ {
461
+ category : 'HARM_CATEGORY_HARASSMENT' ,
462
+ probability : 'NEGLIGIBLE' ,
463
+ probabilityScore : 0.28012377 ,
464
+ severity : 'HARM_SEVERITY_NEGLIGIBLE' ,
465
+ severityScore : 0.112405084 ,
466
+ } ,
467
+ {
468
+ category : 'HARM_CATEGORY_SEXUALLY_EXPLICIT' ,
469
+ probability : 'NEGLIGIBLE' ,
470
+ } ,
471
+ ] ,
472
+ } ,
473
+ } ,
474
+ } ,
368
475
] ;
369
476
for ( const test of testCases ) {
370
477
it ( test . should , ( ) => {
0 commit comments