Skip to content

Commit

Permalink
test: Added StructuredOutputs example like official.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Sep 9, 2024
1 parent bdabb05 commit f2c501f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- 'mkdocs.yml'
- 'examples/**'
- 'src/helpers/GenerateDocs/**'
- 'src/tests/OpenAI.IntegrationTests/Examples/**'
- '.github/workflows/mkdocs.yml'

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace OpenAI.IntegrationTests.Examples;

public partial class Examples
{
[Test]
[Explicit]
public async Task StructuredOutputs()
{
using var api = GetAuthenticatedClient();

MathReasoning? mathReasoning = await api.Chat.CreateChatCompletionAsAsync<MathReasoning>(
messages: ["How can I solve 8x + 7 = -23?"],
model: CreateChatCompletionRequestModel.Gpt4o20240806,
strict: true);

Console.WriteLine($"Final answer: {mathReasoning?.FinalAnswer}");
Console.WriteLine("Reasoning steps:");

foreach (MathReasoningStep step in mathReasoning?.Steps ?? [])
{
Console.WriteLine($" - Explanation: {step.Explanation}");
Console.WriteLine($" Output: {step.Output}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace OpenAI.IntegrationTests.Examples;

// # START EXAMPLE #

public class MathReasoning
{
public MathReasoningStep[] Steps { get; set; } = [];
public string FinalAnswer { get; set; } = string.Empty;
}

public class MathReasoningStep
{
public string Explanation { get; set; } = string.Empty;
public string Output { get; set; } = string.Empty;
}

0 comments on commit f2c501f

Please sign in to comment.