@@ -21,6 +21,10 @@ private class TestTools
2121 {
2222 public static string Echo ( string message ) => message ;
2323 public static int Add ( int a , int b ) => a + b ;
24+ public static double Multiply ( double x , double y ) => x * y ;
25+ public static bool IsGreaterThan ( long value1 , long value2 ) => value1 > value2 ;
26+ public static float Divide ( float numerator , float denominator ) => numerator / denominator ;
27+ public static string ConcatWithBool ( string text , bool flag ) => $ "{ text } :{ flag } ";
2428 }
2529
2630 private Mock < EmbeddingClient > mockEmbeddingClient ;
@@ -37,9 +41,13 @@ public void CanAddLocalTools()
3741 var tools = new ResponseTools ( ) ;
3842 tools . AddFunctionTools ( typeof ( TestTools ) ) ;
3943
40- Assert . That ( tools . Tools , Has . Count . EqualTo ( 2 ) ) ;
44+ Assert . That ( tools . Tools , Has . Count . EqualTo ( 6 ) ) ;
4145 Assert . That ( tools . Tools . Any ( t => ( ( string ) t . GetType ( ) . GetProperty ( "Name" ) . GetValue ( t ) ) . Contains ( "Echo" ) ) ) ;
4246 Assert . That ( tools . Tools . Any ( t => ( ( string ) t . GetType ( ) . GetProperty ( "Name" ) . GetValue ( t ) ) . Contains ( "Add" ) ) ) ;
47+ Assert . That ( tools . Tools . Any ( t => ( ( string ) t . GetType ( ) . GetProperty ( "Name" ) . GetValue ( t ) ) . Contains ( "Multiply" ) ) ) ;
48+ Assert . That ( tools . Tools . Any ( t => ( ( string ) t . GetType ( ) . GetProperty ( "Name" ) . GetValue ( t ) ) . Contains ( "IsGreaterThan" ) ) ) ;
49+ Assert . That ( tools . Tools . Any ( t => ( ( string ) t . GetType ( ) . GetProperty ( "Name" ) . GetValue ( t ) ) . Contains ( "Divide" ) ) ) ;
50+ Assert . That ( tools . Tools . Any ( t => ( ( string ) t . GetType ( ) . GetProperty ( "Name" ) . GetValue ( t ) ) . Contains ( "ConcatWithBool" ) ) ) ;
4351 }
4452
4553 [ Test ]
@@ -48,17 +56,42 @@ public async Task CanCallToolAsync()
4856 var tools = new ResponseTools ( ) ;
4957 tools . AddFunctionTools ( typeof ( TestTools ) ) ;
5058
51- var toolCall = new FunctionCallResponseItem ( "call1" , "Echo" , BinaryData . FromString ( @"{""message"": ""Hello""}" ) ) ;
52- var result = await tools . CallAsync ( toolCall ) ;
53-
54- Assert . That ( result . CallId , Is . EqualTo ( "call1" ) ) ;
55- Assert . That ( result . FunctionOutput , Is . EqualTo ( "Hello" ) ) ;
56-
57- var addCall = new FunctionCallResponseItem ( "call2" , "Add" , BinaryData . FromString ( @"{""a"": 2, ""b"": 3}" ) ) ;
58- result = await tools . CallAsync ( addCall ) ;
59+ var toolCalls = new [ ]
60+ {
61+ new FunctionCallResponseItem ( "call1" , "Echo" , BinaryData . FromString ( @"{""message"": ""Hello""}" ) ) ,
62+ new FunctionCallResponseItem ( "call2" , "Add" , BinaryData . FromString ( @"{""a"": 2, ""b"": 3}" ) ) ,
63+ new FunctionCallResponseItem ( "call3" , "Multiply" , BinaryData . FromString ( @"{""x"": 2.5, ""y"": 3.0}" ) ) ,
64+ new FunctionCallResponseItem ( "call4" , "IsGreaterThan" , BinaryData . FromString ( @"{""value1"": 100, ""value2"": 50}" ) ) ,
65+ new FunctionCallResponseItem ( "call5" , "Divide" , BinaryData . FromString ( @"{""numerator"": 10.0, ""denominator"": 2.0}" ) ) ,
66+ new FunctionCallResponseItem ( "call6" , "ConcatWithBool" , BinaryData . FromString ( @"{""text"": ""Test"", ""flag"": true}" ) )
67+ } ;
5968
60- Assert . That ( result . CallId , Is . EqualTo ( "call2" ) ) ;
61- Assert . That ( result . FunctionOutput , Is . EqualTo ( "5" ) ) ;
69+ foreach ( var toolCall in toolCalls )
70+ {
71+ var result = await tools . CallAsync ( toolCall ) ;
72+ Assert . That ( result . CallId , Is . EqualTo ( toolCall . CallId ) ) ;
73+ switch ( toolCall . CallId )
74+ {
75+ case "call1" :
76+ Assert . That ( result . FunctionOutput , Is . EqualTo ( "Hello" ) ) ;
77+ break ;
78+ case "call2" :
79+ Assert . That ( result . FunctionOutput , Is . EqualTo ( "5" ) ) ;
80+ break ;
81+ case "call3" :
82+ Assert . That ( result . FunctionOutput , Is . EqualTo ( "7.5" ) ) ;
83+ break ;
84+ case "call4" :
85+ Assert . That ( result . FunctionOutput , Is . EqualTo ( "True" ) ) ;
86+ break ;
87+ case "call5" :
88+ Assert . That ( result . FunctionOutput , Is . EqualTo ( "5" ) ) ;
89+ break ;
90+ case "call6" :
91+ Assert . That ( result . FunctionOutput , Is . EqualTo ( "Test:True" ) ) ;
92+ break ;
93+ }
94+ }
6295 }
6396
6497 [ Test ]
@@ -69,9 +102,13 @@ public void CreatesResponseOptionsWithTools()
69102
70103 var options = tools . ToResponseCreationOptions ( ) ;
71104
72- Assert . That ( options . Tools , Has . Count . EqualTo ( 2 ) ) ;
105+ Assert . That ( options . Tools , Has . Count . EqualTo ( 6 ) ) ;
73106 Assert . That ( tools . Tools . Any ( t => ( ( string ) t . GetType ( ) . GetProperty ( "Name" ) . GetValue ( t ) ) . Contains ( "Echo" ) ) ) ;
74107 Assert . That ( tools . Tools . Any ( t => ( ( string ) t . GetType ( ) . GetProperty ( "Name" ) . GetValue ( t ) ) . Contains ( "Add" ) ) ) ;
108+ Assert . That ( tools . Tools . Any ( t => ( ( string ) t . GetType ( ) . GetProperty ( "Name" ) . GetValue ( t ) ) . Contains ( "Multiply" ) ) ) ;
109+ Assert . That ( tools . Tools . Any ( t => ( ( string ) t . GetType ( ) . GetProperty ( "Name" ) . GetValue ( t ) ) . Contains ( "IsGreaterThan" ) ) ) ;
110+ Assert . That ( tools . Tools . Any ( t => ( ( string ) t . GetType ( ) . GetProperty ( "Name" ) . GetValue ( t ) ) . Contains ( "Divide" ) ) ) ;
111+ Assert . That ( tools . Tools . Any ( t => ( ( string ) t . GetType ( ) . GetProperty ( "Name" ) . GetValue ( t ) ) . Contains ( "ConcatWithBool" ) ) ) ;
75112 }
76113
77114 [ Test ]
0 commit comments