Skip to content

Commit

Permalink
Improve OpenAiClientGetStructuredResponseTests
Browse files Browse the repository at this point in the history
  • Loading branch information
rodion-m committed Aug 5, 2023
1 parent 5df6982 commit f50d386
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 93 deletions.
55 changes: 0 additions & 55 deletions OpenAI.ChatGPT.Modules.ChatBot/ChatGptBot.cs

This file was deleted.

7 changes: 0 additions & 7 deletions OpenAI_DotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.ChatGpt.Modules.Stru
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "modules", "modules", "{068E9E67-C2FC-4F8C-B27C-CB3A8FA44BD8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.ChatGPT.Modules.ChatBot", "OpenAI.ChatGPT.Modules.ChatBot\OpenAI.ChatGPT.Modules.ChatBot.csproj", "{18DF620B-CEE4-4DDB-8C70-A2BF95026E14}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -89,10 +87,6 @@ Global
{F2968A66-5672-439E-823E-D35100CA067D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2968A66-5672-439E-823E-D35100CA067D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2968A66-5672-439E-823E-D35100CA067D}.Release|Any CPU.Build.0 = Release|Any CPU
{18DF620B-CEE4-4DDB-8C70-A2BF95026E14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18DF620B-CEE4-4DDB-8C70-A2BF95026E14}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18DF620B-CEE4-4DDB-8C70-A2BF95026E14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18DF620B-CEE4-4DDB-8C70-A2BF95026E14}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -107,6 +101,5 @@ Global
{E303F270-6091-47DE-9260-DAD6122005A7} = {926D63B6-9F6A-45A1-B5B7-5F36352C23AB}
{F2968A66-5672-439E-823E-D35100CA067D} = {068E9E67-C2FC-4F8C-B27C-CB3A8FA44BD8}
{E155D31C-0061-40A3-AD54-93B5DD08836B} = {068E9E67-C2FC-4F8C-B27C-CB3A8FA44BD8}
{18DF620B-CEE4-4DDB-8C70-A2BF95026E14} = {068E9E67-C2FC-4F8C-B27C-CB3A8FA44BD8}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public OpenAiClientGetStructuredResponseTests()
[Fact]
public async void Get_simple_structured_response_from_ChatGPT()
{
var message =
var message =
Dialog.StartAsSystem("What did user input?")
.ThenUser("My name is John, my age is 30, my email is [email protected]");
var response = await _client.GetStructuredResponse<UserInfo>(message);
Expand All @@ -23,70 +23,60 @@ public async void Get_simple_structured_response_from_ChatGPT()
response.Age.Should().Be(30);
response.Email.Should().Be("[email protected]");
}

[Fact]
public async void Get_structured_response_with_ARRAY_from_ChatGPT()
{
var message =
Dialog.StartAsSystem("What did user input?")
.ThenUser("My name is John, my age is 30, my email is [email protected]. I want to buy 2 apple and 3 orange.");
var message = Dialog
.StartAsSystem("What did user input?")
.ThenUser("My name is John, my age is 30, my email is [email protected]. " +
"I want to buy 2 apple and 3 orange.");
var response = await _client.GetStructuredResponse<Order>(message);
response.Should().NotBeNull();
response.UserInfo.Should().NotBeNull();
response.UserInfo!.Name.Should().Be("John");
response.UserInfo.Age.Should().Be(30);
response.UserInfo.Email.Should().Be("[email protected]");

response.Items.Should().HaveCount(2);
response.Items![0].Name.Should().Be("apple");
response.Items[0].Quantity.Should().Be(2);
response.Items[1].Name.Should().Be("orange");
response.Items[1].Quantity.Should().Be(3);
}

[Fact]
public async void Get_structured_response_with_ENUM_from_ChatGPT()
{
var message =
Dialog.StartAsSystem("What did user input?")
.ThenUser("Мой любимый цвет - красный");
var message = Dialog
.StartAsSystem("What did user input?")
.ThenUser("Мой любимый цвет - красный");
var response = await _client.GetStructuredResponse<Thing>(message);
response.Should().NotBeNull();
response.Color.Should().Be(Thing.Colors.Red);
}

[Fact]
public async void Get_structured_response_with_extra_data_from_ChatGPT()
{
var message =
Dialog.StartAsSystem("Return requested data.")
.ThenUser("In what year was the city of Almaty originally founded?");
var message = Dialog
.StartAsSystem("Return requested data.")
.ThenUser("I need info about Almaty city");
var response = await _client.GetStructuredResponse<City>(message);
response.Should().NotBeNull();
//response.Name.Should().Be("Almaty");
response.Name.Should().Be("Almaty");
response.Country.Should().Be("Kazakhstan");
response.YearOfFoundation.Should().Be(1854);
//response.Country.Should().Be("Kazakhstan");
}

[Fact]
public async void Get_structured_response_for_tic_tak_toe_from_ChatGPT_GPT4()
{
var message =
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}]");
var response = await _client.GetStructuredResponse<CellPosition>(message, model: ChatCompletionModels.Gpt4);
response.Should().NotBeNull();
}

private record CellPosition(int Row, int Column);


private class Order
{
public UserInfo? UserInfo { get; set; }
public List<Item>? Items { get; set; }

public record Item(string Name, int Quantity);
}

private class UserInfo
{
public string? Name { get; init; }
Expand All @@ -106,5 +96,4 @@ public enum Colors
}

private record City(string Name, int YearOfFoundation, string Country);
}

}

0 comments on commit f50d386

Please sign in to comment.