@@ -46,6 +46,7 @@ describe('doGenerate', () => {
46
46
47
47
function prepareJsonResponse ( {
48
48
content = '' ,
49
+ reasoning,
49
50
tool_calls,
50
51
function_call,
51
52
usage = {
@@ -59,6 +60,7 @@ describe('doGenerate', () => {
59
60
model = 'gemma2-9b-it' ,
60
61
} : {
61
62
content ?: string ;
63
+ reasoning ?: string ;
62
64
tool_calls ?: Array < {
63
65
id : string ;
64
66
type : 'function' ;
@@ -92,6 +94,7 @@ describe('doGenerate', () => {
92
94
message : {
93
95
role : 'assistant' ,
94
96
content,
97
+ reasoning,
95
98
tool_calls,
96
99
function_call,
97
100
} ,
@@ -115,6 +118,20 @@ describe('doGenerate', () => {
115
118
expect ( text ) . toStrictEqual ( 'Hello, World!' ) ;
116
119
} ) ;
117
120
121
+ it ( 'should extract reasoning' , async ( ) => {
122
+ prepareJsonResponse ( {
123
+ reasoning : 'This is a test reasoning' ,
124
+ } ) ;
125
+
126
+ const { reasoning } = await model . doGenerate ( {
127
+ inputFormat : 'prompt' ,
128
+ mode : { type : 'regular' } ,
129
+ prompt : TEST_PROMPT ,
130
+ } ) ;
131
+
132
+ expect ( reasoning ) . toStrictEqual ( 'This is a test reasoning' ) ;
133
+ } ) ;
134
+
118
135
it ( 'should extract usage' , async ( ) => {
119
136
prepareJsonResponse ( {
120
137
content : '' ,
@@ -249,13 +266,17 @@ describe('doGenerate', () => {
249
266
inputFormat : 'prompt' ,
250
267
mode : { type : 'regular' } ,
251
268
prompt : TEST_PROMPT ,
269
+ providerMetadata : {
270
+ groq : { reasoningFormat : 'hidden' } ,
271
+ } ,
252
272
} ) ;
253
273
254
274
expect ( await server . getRequestBodyJson ( ) ) . toStrictEqual ( {
255
275
model : 'gemma2-9b-it' ,
256
276
messages : [ { role : 'user' , content : 'Hello' } ] ,
257
277
parallel_tool_calls : false ,
258
278
user : 'test-user-id' ,
279
+ reasoning_format : 'hidden' ,
259
280
} ) ;
260
281
} ) ;
261
282
@@ -489,7 +510,6 @@ describe('doStream', () => {
489
510
modelId : 'gemma2-9b-it' ,
490
511
timestamp : new Date ( '2023-12-15T16:17:00.000Z' ) ,
491
512
} ,
492
- { type : 'text-delta' , textDelta : '' } ,
493
513
{ type : 'text-delta' , textDelta : 'Hello' } ,
494
514
{ type : 'text-delta' , textDelta : ', ' } ,
495
515
{ type : 'text-delta' , textDelta : 'World!' } ,
@@ -501,6 +521,50 @@ describe('doStream', () => {
501
521
] ) ;
502
522
} ) ;
503
523
524
+ it ( 'should stream reasoning deltas' , async ( ) => {
525
+ server . responseChunks = [
526
+ `data: {"id":"chatcmpl-e7f8e220-656c-4455-a132-dacfc1370798","object":"chat.completion.chunk","created":1702657020,"model":"gemma2-9b-it",` +
527
+ `"system_fingerprint":null,"choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}\n\n` ,
528
+ `data: {"id":"chatcmpl-e7f8e220-656c-4455-a132-dacfc1370798","object":"chat.completion.chunk","created":1702657020,"model":"gemma2-9b-it",` +
529
+ `"system_fingerprint":null,"choices":[{"index":1,"delta":{"reasoning":"I think,"},"finish_reason":null}]}\n\n` ,
530
+ `data: {"id":"chatcmpl-e7f8e220-656c-4455-a132-dacfc1370798","object":"chat.completion.chunk","created":1702657020,"model":"gemma2-9b-it",` +
531
+ `"system_fingerprint":null,"choices":[{"index":1,"delta":{"reasoning":"therefore I am."},"finish_reason":null}]}\n\n` ,
532
+ `data: {"id":"chatcmpl-e7f8e220-656c-4455-a132-dacfc1370798","object":"chat.completion.chunk","created":1702657020,"model":"gemma2-9b-it",` +
533
+ `"system_fingerprint":null,"choices":[{"index":1,"delta":{"content":"Hello"},"finish_reason":null}]}\n\n` ,
534
+ `data: {"id":"chatcmpl-e7f8e220-656c-4455-a132-dacfc1370798","object":"chat.completion.chunk","created":1702657020,"model":"gemma2-9b-it",` +
535
+ `"system_fingerprint":null,"choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}\n\n` ,
536
+ `data: {"id":"chatcmpl-e7f8e220-656c-4455-a132-dacfc1370798","object":"chat.completion.chunk","created":1729171479,"model":"gemma2-9b-it",` +
537
+ `"system_fingerprint":"fp_10c08bf97d","choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}],` +
538
+ `"x_groq":{"id":"req_01jadadp0femyae9kav1gpkhe8","usage":{"queue_time":0.061348671,"prompt_tokens":18,"prompt_time":0.000211569,` +
539
+ `"completion_tokens":439,"completion_time":0.798181818,"total_tokens":457,"total_time":0.798393387}}}\n\n` ,
540
+ 'data: [DONE]\n\n' ,
541
+ ] ;
542
+
543
+ const { stream } = await model . doStream ( {
544
+ inputFormat : 'prompt' ,
545
+ mode : { type : 'regular' } ,
546
+ prompt : TEST_PROMPT ,
547
+ } ) ;
548
+
549
+ // note: space moved to last chunk bc of trimming
550
+ expect ( await convertReadableStreamToArray ( stream ) ) . toStrictEqual ( [
551
+ {
552
+ type : 'response-metadata' ,
553
+ id : 'chatcmpl-e7f8e220-656c-4455-a132-dacfc1370798' ,
554
+ modelId : 'gemma2-9b-it' ,
555
+ timestamp : new Date ( '2023-12-15T16:17:00.000Z' ) ,
556
+ } ,
557
+ { type : 'reasoning' , textDelta : 'I think,' } ,
558
+ { type : 'reasoning' , textDelta : 'therefore I am.' } ,
559
+ { type : 'text-delta' , textDelta : 'Hello' } ,
560
+ {
561
+ type : 'finish' ,
562
+ finishReason : 'stop' ,
563
+ usage : { promptTokens : 18 , completionTokens : 439 } ,
564
+ } ,
565
+ ] ) ;
566
+ } ) ;
567
+
504
568
it ( 'should stream tool deltas' , async ( ) => {
505
569
server . responseChunks = [
506
570
`data: {"id":"chatcmpl-e7f8e220-656c-4455-a132-dacfc1370798","object":"chat.completion.chunk","created":1711357598,"model":"gemma2-9b-it",` +
@@ -828,10 +892,6 @@ describe('doStream', () => {
828
892
modelId : 'meta/llama-3.1-8b-instruct:fp8' ,
829
893
timestamp : new Date ( '2024-12-02T17:57:21.000Z' ) ,
830
894
} ,
831
- {
832
- type : 'text-delta' ,
833
- textDelta : '' ,
834
- } ,
835
895
{
836
896
type : 'tool-call-delta' ,
837
897
toolCallId : 'chatcmpl-tool-b3b307239370432d9910d4b79b4dbbaa' ,
0 commit comments