Skip to content

Commit f50d386

Browse files
committed
Improve OpenAiClientGetStructuredResponseTests
1 parent 5df6982 commit f50d386

File tree

3 files changed

+20
-93
lines changed

3 files changed

+20
-93
lines changed

OpenAI.ChatGPT.Modules.ChatBot/ChatGptBot.cs

Lines changed: 0 additions & 55 deletions
This file was deleted.

OpenAI_DotNet.sln

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.ChatGpt.Modules.Stru
3333
EndProject
3434
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "modules", "modules", "{068E9E67-C2FC-4F8C-B27C-CB3A8FA44BD8}"
3535
EndProject
36-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.ChatGPT.Modules.ChatBot", "OpenAI.ChatGPT.Modules.ChatBot\OpenAI.ChatGPT.Modules.ChatBot.csproj", "{18DF620B-CEE4-4DDB-8C70-A2BF95026E14}"
37-
EndProject
3836
Global
3937
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4038
Debug|Any CPU = Debug|Any CPU
@@ -89,10 +87,6 @@ Global
8987
{F2968A66-5672-439E-823E-D35100CA067D}.Debug|Any CPU.Build.0 = Debug|Any CPU
9088
{F2968A66-5672-439E-823E-D35100CA067D}.Release|Any CPU.ActiveCfg = Release|Any CPU
9189
{F2968A66-5672-439E-823E-D35100CA067D}.Release|Any CPU.Build.0 = Release|Any CPU
92-
{18DF620B-CEE4-4DDB-8C70-A2BF95026E14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
93-
{18DF620B-CEE4-4DDB-8C70-A2BF95026E14}.Debug|Any CPU.Build.0 = Debug|Any CPU
94-
{18DF620B-CEE4-4DDB-8C70-A2BF95026E14}.Release|Any CPU.ActiveCfg = Release|Any CPU
95-
{18DF620B-CEE4-4DDB-8C70-A2BF95026E14}.Release|Any CPU.Build.0 = Release|Any CPU
9690
EndGlobalSection
9791
GlobalSection(SolutionProperties) = preSolution
9892
HideSolutionNode = FALSE
@@ -107,6 +101,5 @@ Global
107101
{E303F270-6091-47DE-9260-DAD6122005A7} = {926D63B6-9F6A-45A1-B5B7-5F36352C23AB}
108102
{F2968A66-5672-439E-823E-D35100CA067D} = {068E9E67-C2FC-4F8C-B27C-CB3A8FA44BD8}
109103
{E155D31C-0061-40A3-AD54-93B5DD08836B} = {068E9E67-C2FC-4F8C-B27C-CB3A8FA44BD8}
110-
{18DF620B-CEE4-4DDB-8C70-A2BF95026E14} = {068E9E67-C2FC-4F8C-B27C-CB3A8FA44BD8}
111104
EndGlobalSection
112105
EndGlobal

tests/OpenAI.ChatGpt.IntegrationTests/OpenAiClientTests/OpenAiClient_GetStructuredResponse.cs

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public OpenAiClientGetStructuredResponseTests()
1414
[Fact]
1515
public async void Get_simple_structured_response_from_ChatGPT()
1616
{
17-
var message =
17+
var message =
1818
Dialog.StartAsSystem("What did user input?")
1919
.ThenUser("My name is John, my age is 30, my email is [email protected]");
2020
var response = await _client.GetStructuredResponse<UserInfo>(message);
@@ -23,70 +23,60 @@ public async void Get_simple_structured_response_from_ChatGPT()
2323
response.Age.Should().Be(30);
2424
response.Email.Should().Be("[email protected]");
2525
}
26-
26+
2727
[Fact]
2828
public async void Get_structured_response_with_ARRAY_from_ChatGPT()
2929
{
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.");
3334
var response = await _client.GetStructuredResponse<Order>(message);
3435
response.Should().NotBeNull();
3536
response.UserInfo.Should().NotBeNull();
3637
response.UserInfo!.Name.Should().Be("John");
3738
response.UserInfo.Age.Should().Be(30);
3839
response.UserInfo.Email.Should().Be("[email protected]");
39-
40+
4041
response.Items.Should().HaveCount(2);
4142
response.Items![0].Name.Should().Be("apple");
4243
response.Items[0].Quantity.Should().Be(2);
4344
response.Items[1].Name.Should().Be("orange");
4445
response.Items[1].Quantity.Should().Be(3);
4546
}
46-
47+
4748
[Fact]
4849
public async void Get_structured_response_with_ENUM_from_ChatGPT()
4950
{
50-
var message =
51-
Dialog.StartAsSystem("What did user input?")
52-
.ThenUser("Мой любимый цвет - красный");
51+
var message = Dialog
52+
.StartAsSystem("What did user input?")
53+
.ThenUser("Мой любимый цвет - красный");
5354
var response = await _client.GetStructuredResponse<Thing>(message);
5455
response.Should().NotBeNull();
5556
response.Color.Should().Be(Thing.Colors.Red);
5657
}
57-
58+
5859
[Fact]
5960
public async void Get_structured_response_with_extra_data_from_ChatGPT()
6061
{
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");
6465
var response = await _client.GetStructuredResponse<City>(message);
6566
response.Should().NotBeNull();
66-
//response.Name.Should().Be("Almaty");
67+
response.Name.Should().Be("Almaty");
68+
response.Country.Should().Be("Kazakhstan");
6769
response.YearOfFoundation.Should().Be(1854);
68-
//response.Country.Should().Be("Kazakhstan");
6970
}
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+
8272
private class Order
8373
{
8474
public UserInfo? UserInfo { get; set; }
8575
public List<Item>? Items { get; set; }
8676

8777
public record Item(string Name, int Quantity);
8878
}
89-
79+
9080
private class UserInfo
9181
{
9282
public string? Name { get; init; }
@@ -106,5 +96,4 @@ public enum Colors
10696
}
10797

10898
private record City(string Name, int YearOfFoundation, string Country);
109-
}
110-
99+
}

0 commit comments

Comments
 (0)