@@ -14,7 +14,7 @@ public OpenAiClientGetStructuredResponseTests()
14
14
[ Fact ]
15
15
public async void Get_simple_structured_response_from_ChatGPT ( )
16
16
{
17
- var message =
17
+ var message =
18
18
Dialog . StartAsSystem ( "What did user input?" )
19
19
. ThenUser ( "My name is John, my age is 30, my email is [email protected] " ) ;
20
20
var response = await _client . GetStructuredResponse < UserInfo > ( message ) ;
@@ -23,70 +23,60 @@ public async void Get_simple_structured_response_from_ChatGPT()
23
23
response . Age . Should ( ) . Be ( 30 ) ;
24
24
response . Email . Should ( ) . Be ( "[email protected] " ) ;
25
25
}
26
-
26
+
27
27
[ Fact ]
28
28
public async void Get_structured_response_with_ARRAY_from_ChatGPT ( )
29
29
{
30
- var message =
31
- Dialog . StartAsSystem ( "What did user input?" )
32
- . ThenUser ( "My name is John, my age is 30, my email is [email protected] . I want to buy 2 apple and 3 orange." ) ;
30
+ var message = Dialog
31
+ . StartAsSystem ( "What did user input?" )
32
+ . ThenUser ( "My name is John, my age is 30, my email is [email protected] . " +
33
+ "I want to buy 2 apple and 3 orange." ) ;
33
34
var response = await _client . GetStructuredResponse < Order > ( message ) ;
34
35
response . Should ( ) . NotBeNull ( ) ;
35
36
response . UserInfo . Should ( ) . NotBeNull ( ) ;
36
37
response . UserInfo ! . Name . Should ( ) . Be ( "John" ) ;
37
38
response . UserInfo . Age . Should ( ) . Be ( 30 ) ;
38
39
response . UserInfo . Email . Should ( ) . Be ( "[email protected] " ) ;
39
-
40
+
40
41
response . Items . Should ( ) . HaveCount ( 2 ) ;
41
42
response . Items ! [ 0 ] . Name . Should ( ) . Be ( "apple" ) ;
42
43
response . Items [ 0 ] . Quantity . Should ( ) . Be ( 2 ) ;
43
44
response . Items [ 1 ] . Name . Should ( ) . Be ( "orange" ) ;
44
45
response . Items [ 1 ] . Quantity . Should ( ) . Be ( 3 ) ;
45
46
}
46
-
47
+
47
48
[ Fact ]
48
49
public async void Get_structured_response_with_ENUM_from_ChatGPT ( )
49
50
{
50
- var message =
51
- Dialog . StartAsSystem ( "What did user input?" )
52
- . ThenUser ( "Мой любимый цвет - красный" ) ;
51
+ var message = Dialog
52
+ . StartAsSystem ( "What did user input?" )
53
+ . ThenUser ( "Мой любимый цвет - красный" ) ;
53
54
var response = await _client . GetStructuredResponse < Thing > ( message ) ;
54
55
response . Should ( ) . NotBeNull ( ) ;
55
56
response . Color . Should ( ) . Be ( Thing . Colors . Red ) ;
56
57
}
57
-
58
+
58
59
[ Fact ]
59
60
public async void Get_structured_response_with_extra_data_from_ChatGPT ( )
60
61
{
61
- var message =
62
- Dialog . StartAsSystem ( "Return requested data." )
63
- . ThenUser ( "In what year was the city of Almaty originally founded? " ) ;
62
+ var message = Dialog
63
+ . StartAsSystem ( "Return requested data." )
64
+ . ThenUser ( "I need info about Almaty city " ) ;
64
65
var response = await _client . GetStructuredResponse < City > ( message ) ;
65
66
response . Should ( ) . NotBeNull ( ) ;
66
- //response.Name.Should().Be("Almaty");
67
+ response . Name . Should ( ) . Be ( "Almaty" ) ;
68
+ response . Country . Should ( ) . Be ( "Kazakhstan" ) ;
67
69
response . YearOfFoundation . Should ( ) . Be ( 1854 ) ;
68
- //response.Country.Should().Be("Kazakhstan");
69
70
}
70
-
71
- [ Fact ]
72
- public async void Get_structured_response_for_tic_tak_toe_from_ChatGPT_GPT4 ( )
73
- {
74
- var message =
75
- Dialog . StartAsSystem ( "This is a game of tic tac toe. X goes first. Your turn is O. What is your next move? Board: [{\" Row\" :0,\" Column\" :0},{\" Row\" :0,\" Column\" :1},{\" Row\" :0,\" Column\" :2},{\" Row\" :1,\" Column\" :0},{\" Row\" :1,\" Column\" :1},{\" Row\" :1,\" Column\" :2},{\" Row\" :2,\" Column\" :0},{\" Row\" :2,\" Column\" :1},{\" Row\" :2,\" Column\" :2}]" ) ;
76
- var response = await _client . GetStructuredResponse < CellPosition > ( message , model : ChatCompletionModels . Gpt4 ) ;
77
- response . Should ( ) . NotBeNull ( ) ;
78
- }
79
-
80
- private record CellPosition ( int Row , int Column ) ;
81
-
71
+
82
72
private class Order
83
73
{
84
74
public UserInfo ? UserInfo { get ; set ; }
85
75
public List < Item > ? Items { get ; set ; }
86
76
87
77
public record Item ( string Name , int Quantity ) ;
88
78
}
89
-
79
+
90
80
private class UserInfo
91
81
{
92
82
public string ? Name { get ; init ; }
@@ -106,5 +96,4 @@ public enum Colors
106
96
}
107
97
108
98
private record City ( string Name , int YearOfFoundation , string Country ) ;
109
- }
110
-
99
+ }
0 commit comments