@@ -116,7 +116,6 @@ describe('InferenceGatewayClient', () => {
116
116
{ role : MessageRole . system , content : 'You are a helpful assistant' } ,
117
117
{ role : MessageRole . user , content : 'Hello' } ,
118
118
] ,
119
- stream : false ,
120
119
} ;
121
120
122
121
const mockResponse : SchemaCreateChatCompletionResponse = {
@@ -152,7 +151,7 @@ describe('InferenceGatewayClient', () => {
152
151
'http://localhost:8080/v1/chat/completions' ,
153
152
expect . objectContaining ( {
154
153
method : 'POST' ,
155
- body : JSON . stringify ( mockRequest ) ,
154
+ body : JSON . stringify ( { ... mockRequest , stream : false } ) ,
156
155
} )
157
156
) ;
158
157
} ) ;
@@ -161,7 +160,6 @@ describe('InferenceGatewayClient', () => {
161
160
const mockRequest = {
162
161
model : 'claude-3-opus-20240229' ,
163
162
messages : [ { role : MessageRole . user , content : 'Hello' } ] ,
164
- stream : false ,
165
163
} ;
166
164
167
165
const mockResponse : SchemaCreateChatCompletionResponse = {
@@ -200,7 +198,7 @@ describe('InferenceGatewayClient', () => {
200
198
'http://localhost:8080/v1/chat/completions?provider=anthropic' ,
201
199
expect . objectContaining ( {
202
200
method : 'POST' ,
203
- body : JSON . stringify ( mockRequest ) ,
201
+ body : JSON . stringify ( { ... mockRequest , stream : false } ) ,
204
202
} )
205
203
) ;
206
204
} ) ;
@@ -211,7 +209,6 @@ describe('InferenceGatewayClient', () => {
211
209
const mockRequest = {
212
210
model : 'gpt-4o' ,
213
211
messages : [ { role : MessageRole . user , content : 'Hello' } ] ,
214
- stream : true ,
215
212
} ;
216
213
217
214
const mockStream = new TransformStream ( ) ;
@@ -258,6 +255,9 @@ describe('InferenceGatewayClient', () => {
258
255
body : JSON . stringify ( {
259
256
...mockRequest ,
260
257
stream : true ,
258
+ stream_options : {
259
+ include_usage : true ,
260
+ } ,
261
261
} ) ,
262
262
} )
263
263
) ;
@@ -267,7 +267,6 @@ describe('InferenceGatewayClient', () => {
267
267
const mockRequest = {
268
268
model : 'gpt-4o' ,
269
269
messages : [ { role : MessageRole . user , content : 'Hello' } ] ,
270
- stream : true ,
271
270
} ;
272
271
const mockStream = new TransformStream ( ) ;
273
272
const writer = mockStream . writable . getWriter ( ) ;
@@ -318,6 +317,9 @@ describe('InferenceGatewayClient', () => {
318
317
body : JSON . stringify ( {
319
318
...mockRequest ,
320
319
stream : true ,
320
+ stream_options : {
321
+ include_usage : true ,
322
+ } ,
321
323
} ) ,
322
324
} )
323
325
) ;
@@ -341,7 +343,6 @@ describe('InferenceGatewayClient', () => {
341
343
} ,
342
344
} ,
343
345
] ,
344
- stream : true ,
345
346
} ;
346
347
347
348
const mockStream = new TransformStream ( ) ;
@@ -390,13 +391,25 @@ describe('InferenceGatewayClient', () => {
390
391
} ,
391
392
} ) ;
392
393
expect ( callbacks . onFinish ) . toHaveBeenCalledTimes ( 1 ) ;
394
+ expect ( mockFetch ) . toHaveBeenCalledWith (
395
+ 'http://localhost:8080/v1/chat/completions' ,
396
+ expect . objectContaining ( {
397
+ method : 'POST' ,
398
+ body : JSON . stringify ( {
399
+ ...mockRequest ,
400
+ stream : true ,
401
+ stream_options : {
402
+ include_usage : true ,
403
+ } ,
404
+ } ) ,
405
+ } )
406
+ ) ;
393
407
} ) ;
394
408
395
409
it ( 'should handle errors in streaming chat completions' , async ( ) => {
396
410
const mockRequest = {
397
411
model : 'gpt-4o' ,
398
412
messages : [ { role : MessageRole . user , content : 'Hello' } ] ,
399
- stream : true ,
400
413
} ;
401
414
402
415
mockFetch . mockResolvedValueOnce ( {
@@ -420,10 +433,6 @@ describe('InferenceGatewayClient', () => {
420
433
const mockRequest = {
421
434
model : 'gpt-4o' ,
422
435
messages : [ { role : MessageRole . user , content : 'Hello' } ] ,
423
- stream : true ,
424
- stream_options : {
425
- include_usage : true ,
426
- } ,
427
436
} ;
428
437
429
438
const mockStream = new TransformStream ( ) ;
@@ -478,6 +487,9 @@ describe('InferenceGatewayClient', () => {
478
487
body : JSON . stringify ( {
479
488
...mockRequest ,
480
489
stream : true ,
490
+ stream_options : {
491
+ include_usage : true ,
492
+ } ,
481
493
} ) ,
482
494
} )
483
495
) ;
0 commit comments