1
+ using System . IO ;
1
2
using System . Net ;
2
3
using System . Text ;
3
4
using System . Text . Json ;
@@ -390,8 +391,8 @@ public async Task Receives_Response_Message_With_ToolsCalls()
390
391
"eval_count": 28,
391
392
"eval_duration": 4602334000
392
393
}
393
- """ . ReplaceLineEndings ( "" ) ; // the JSON stream reader reads by line, so we need to make this one single line
394
-
394
+ """ . ReplaceLineEndings ( "" ) ; // the JSON stream reader reads by line, so we need to make this one single line
395
+
395
396
await using var stream = new MemoryStream ( ) ;
396
397
397
398
await using var writer = new StreamWriter ( stream , leaveOpen : true ) ;
@@ -407,7 +408,8 @@ public async Task Receives_Response_Message_With_ToolsCalls()
407
408
408
409
var chat = new ChatRequest
409
410
{
410
- Model = "llama3.1:latest" ,
411
+ Model = "llama3.1:latest" ,
412
+ Stream = false ,
411
413
Messages = [
412
414
new ( ChatRole . User , "How is the weather in LA?" ) ,
413
415
] ,
@@ -466,6 +468,66 @@ public async Task Receives_Response_Message_With_ToolsCalls()
466
468
467
469
toolsFunction . Arguments . ElementAt ( 2 ) . Key . Should ( ) . Be ( "number" ) ;
468
470
toolsFunction . Arguments . ElementAt ( 2 ) . Value . ToString ( ) . Should ( ) . Be ( "42" ) ;
471
+ }
472
+
473
+ [ Test , NonParallelizable ]
474
+ public async Task Response_Streaming_Message_With_ToolsCalls_Throws_Not_Supported ( )
475
+ {
476
+ _response = new HttpResponseMessage
477
+ {
478
+ StatusCode = HttpStatusCode . OK ,
479
+ Content = new StringContent ( string . Empty )
480
+ } ;
481
+
482
+ var request = new ChatRequest
483
+ {
484
+ Model = "llama3.1:latest" ,
485
+ Messages = [
486
+ new ( ChatRole . User , "How is the weather in LA?" ) ,
487
+ ] ,
488
+ Tools = [
489
+ new Tool
490
+ {
491
+ Function = new Function
492
+ {
493
+ Description = "Get the current weather for a location" ,
494
+ Name = "get_current_weather" ,
495
+ Parameters = new Parameters
496
+ {
497
+ Properties = new Dictionary < string , Properties >
498
+ {
499
+ [ "location" ] = new ( )
500
+ {
501
+ Type = "string" ,
502
+ Description = "The location to get the weather for, e.g. San Francisco, CA"
503
+ } ,
504
+ [ "format" ] = new ( )
505
+ {
506
+ Type = "string" ,
507
+ Description = "The format to return the weather in, e.g. 'celsius' or 'fahrenheit'" ,
508
+ Enum = [ "celsius" , "fahrenheit" ]
509
+ } ,
510
+ [ "number" ] = new ( )
511
+ {
512
+ Type = "integer" ,
513
+ Description = "The number of the day to get the weather for, e.g. 42"
514
+ }
515
+ } ,
516
+ Required = [ "location" , "format" ] ,
517
+ }
518
+ } ,
519
+ Type = "function"
520
+ }
521
+ ]
522
+ } ;
523
+
524
+ var act = async ( ) =>
525
+ {
526
+ var enumerator = _client . ChatAsync ( request , CancellationToken . None ) . GetAsyncEnumerator ( ) ;
527
+ await enumerator . MoveNextAsync ( ) ;
528
+ } ;
529
+
530
+ await act . Should ( ) . ThrowAsync < NotSupportedException > ( ) ;
469
531
}
470
532
}
471
533
@@ -528,7 +590,7 @@ public async Task Throws_Known_Exception_For_Models_That_Dont_Support_Tools()
528
590
Content = new StringContent ( "{ error: llama2 does not support tools }" )
529
591
} ;
530
592
531
- var act = ( ) => _client . ChatAsync ( new ChatRequest ( ) , CancellationToken . None ) . StreamToEndAsync ( ) ;
593
+ var act = ( ) => _client . ChatAsync ( new ChatRequest ( ) { Stream = false } , CancellationToken . None ) . StreamToEndAsync ( ) ;
532
594
await act . Should ( ) . ThrowAsync < ModelDoesNotSupportToolsException > ( ) ;
533
595
}
534
596
0 commit comments