@@ -15,74 +15,83 @@ public partial class Tests
1515
1616 private async Task ChatClient_CustomProvider_GetResponseAsync ( CustomProvider provider )
1717 {
18- var ( api , model ) = GetAuthorizedChatApi ( provider ) ;
19- using var _ = api ;
20- Meai . IChatClient chatClient = api ;
21-
22- var response = await chatClient . GetResponseAsync (
23- [ new Meai . ChatMessage ( Meai . ChatRole . User , "Say hello in exactly 3 words." ) ] ,
24- new Meai . ChatOptions { ModelId = model } ) ;
25-
26- response . Should ( ) . NotBeNull ( ) ;
27- response . Messages . Should ( ) . NotBeEmpty ( ) ;
28- var text = response . Messages [ 0 ] . Text ;
29- text . Should ( ) . NotBeNullOrWhiteSpace ( ) ;
30- Console . WriteLine ( $ "[{ provider } ] { text } ") ;
18+ await ExecuteProviderAwareAsync ( provider , async ( ) =>
19+ {
20+ var ( api , model ) = GetAuthorizedChatApi ( provider ) ;
21+ using var _ = api ;
22+ Meai . IChatClient chatClient = api ;
23+
24+ var response = await chatClient . GetResponseAsync (
25+ [ new Meai . ChatMessage ( Meai . ChatRole . User , "Say hello in exactly 3 words." ) ] ,
26+ new Meai . ChatOptions { ModelId = model } ) ;
27+
28+ response . Should ( ) . NotBeNull ( ) ;
29+ response . Messages . Should ( ) . NotBeEmpty ( ) ;
30+ var text = response . Messages [ 0 ] . Text ;
31+ text . Should ( ) . NotBeNullOrWhiteSpace ( ) ;
32+ Console . WriteLine ( $ "[{ provider } ] { text } ") ;
33+ } ) . ConfigureAwait ( false ) ;
3134 }
3235
3336 private async Task ChatClient_CustomProvider_StreamingAsync ( CustomProvider provider )
3437 {
35- var ( api , model ) = GetAuthorizedChatApi ( provider ) ;
36- using var _ = api ;
37- Meai . IChatClient chatClient = api ;
38-
39- var updates = new List < Meai . ChatResponseUpdate > ( ) ;
40- await foreach ( var update in chatClient . GetStreamingResponseAsync (
41- [ new Meai . ChatMessage ( Meai . ChatRole . User , "Count from 1 to 5." ) ] ,
42- new Meai . ChatOptions { ModelId = model } ) )
38+ await ExecuteProviderAwareAsync ( provider , async ( ) =>
4339 {
44- updates . Add ( update ) ;
45- }
40+ var ( api , model ) = GetAuthorizedChatApi ( provider ) ;
41+ using var _ = api ;
42+ Meai . IChatClient chatClient = api ;
43+
44+ var updates = new List < Meai . ChatResponseUpdate > ( ) ;
45+ await foreach ( var update in chatClient . GetStreamingResponseAsync (
46+ [ new Meai . ChatMessage ( Meai . ChatRole . User , "Count from 1 to 5." ) ] ,
47+ new Meai . ChatOptions { ModelId = model } ) )
48+ {
49+ updates . Add ( update ) ;
50+ }
4651
47- updates . Should ( ) . NotBeEmpty ( ) ;
48- Console . WriteLine ( $ "[{ provider } ] Got { updates . Count } streaming updates") ;
52+ updates . Should ( ) . NotBeEmpty ( ) ;
53+ Console . WriteLine ( $ "[{ provider } ] Got { updates . Count } streaming updates") ;
54+ } ) . ConfigureAwait ( false ) ;
4955 }
5056
5157 private async Task ChatClient_CustomProvider_ToolCallingAsync ( CustomProvider provider )
5258 {
53- var ( api , model ) = GetAuthorizedChatApi ( provider ) ;
54- using var _ = api ;
55- Meai . IChatClient chatClient = api ;
56-
57- var tool = Meai . AIFunctionFactory . Create (
58- ( string city ) => city switch
59- {
60- "Paris" => "22°C, sunny" ,
61- "London" => "15°C, cloudy" ,
62- _ => "Unknown" ,
63- } ,
64- name : "GetWeather" ,
65- description : "Gets the current weather for a city" ) ;
66-
67- var response = await chatClient . GetResponseAsync (
68- [ new Meai . ChatMessage ( Meai . ChatRole . User , "What's the weather in Paris?" ) ] ,
69- new Meai . ChatOptions
70- {
71- ModelId = model ,
72- Tools = [ tool ] ,
73- } ) ;
74-
75- response . Should ( ) . NotBeNull ( ) ;
76- response . FinishReason . Should ( ) . Be ( Meai . ChatFinishReason . ToolCalls ) ;
77-
78- var functionCall = response . Messages
79- . SelectMany ( m => m . Contents )
80- . OfType < Meai . FunctionCallContent > ( )
81- . FirstOrDefault ( ) ;
82-
83- functionCall . Should ( ) . NotBeNull ( ) ;
84- functionCall ! . Name . Should ( ) . Be ( "GetWeather" ) ;
85- Console . WriteLine ( $ "[{ provider } ] Tool call: { functionCall . Name } ({ string . Join ( ", " , functionCall . Arguments ? . Select ( kv => $ "{ kv . Key } ={ kv . Value } ") ?? [ ] ) } )") ;
59+ await ExecuteProviderAwareAsync ( provider , async ( ) =>
60+ {
61+ var ( api , model ) = GetAuthorizedChatApi ( provider ) ;
62+ using var _ = api ;
63+ Meai . IChatClient chatClient = api ;
64+
65+ var tool = Meai . AIFunctionFactory . Create (
66+ ( string city ) => city switch
67+ {
68+ "Paris" => "22°C, sunny" ,
69+ "London" => "15°C, cloudy" ,
70+ _ => "Unknown" ,
71+ } ,
72+ name : "GetWeather" ,
73+ description : "Gets the current weather for a city" ) ;
74+
75+ var response = await chatClient . GetResponseAsync (
76+ [ new Meai . ChatMessage ( Meai . ChatRole . User , "What's the weather in Paris?" ) ] ,
77+ new Meai . ChatOptions
78+ {
79+ ModelId = model ,
80+ Tools = [ tool ] ,
81+ } ) ;
82+
83+ response . Should ( ) . NotBeNull ( ) ;
84+ response . FinishReason . Should ( ) . Be ( Meai . ChatFinishReason . ToolCalls ) ;
85+
86+ var functionCall = response . Messages
87+ . SelectMany ( m => m . Contents )
88+ . OfType < Meai . FunctionCallContent > ( )
89+ . FirstOrDefault ( ) ;
90+
91+ functionCall . Should ( ) . NotBeNull ( ) ;
92+ functionCall ! . Name . Should ( ) . Be ( "GetWeather" ) ;
93+ Console . WriteLine ( $ "[{ provider } ] Tool call: { functionCall . Name } ({ string . Join ( ", " , functionCall . Arguments ? . Select ( kv => $ "{ kv . Key } ={ kv . Value } ") ?? [ ] ) } )") ;
94+ } ) . ConfigureAwait ( false ) ;
8695 }
8796
8897 // ═══════════════════════════════════════════════════════════════
0 commit comments