From b8ec620316c66ce9f7807c2efe9e2058ada1c791 Mon Sep 17 00:00:00 2001 From: Scott Addie <10702007+scottaddie@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:00:33 -0500 Subject: [PATCH] Simplify structured outputs sample code (#236) * Simplify structured outputs sample code * Update README sample --- README.md | 4 ++-- examples/Chat/Example06_StructuredOutputs.cs | 4 ++-- examples/Chat/Example06_StructuredOutputsAsync.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 019d7fae..a00a238c 100644 --- a/README.md +++ b/README.md @@ -342,12 +342,12 @@ ChatCompletion completion = client.CompleteChat(messages, options); using JsonDocument structuredJson = JsonDocument.Parse(completion.Content[0].Text); -Console.WriteLine($"Final answer: {structuredJson.RootElement.GetProperty("final_answer").GetString()}"); +Console.WriteLine($"Final answer: {structuredJson.RootElement.GetProperty("final_answer")}"); Console.WriteLine("Reasoning steps:"); foreach (JsonElement stepElement in structuredJson.RootElement.GetProperty("steps").EnumerateArray()) { - Console.WriteLine($" - Explanation: {stepElement.GetProperty("explanation").GetString()}"); + Console.WriteLine($" - Explanation: {stepElement.GetProperty("explanation")}"); Console.WriteLine($" Output: {stepElement.GetProperty("output")}"); } ``` diff --git a/examples/Chat/Example06_StructuredOutputs.cs b/examples/Chat/Example06_StructuredOutputs.cs index 37dd7b7c..71839331 100644 --- a/examples/Chat/Example06_StructuredOutputs.cs +++ b/examples/Chat/Example06_StructuredOutputs.cs @@ -51,12 +51,12 @@ public void Example06_StructuredOutputs() using JsonDocument structuredJson = JsonDocument.Parse(completion.Content[0].Text); - Console.WriteLine($"Final answer: {structuredJson.RootElement.GetProperty("final_answer").GetString()}"); + Console.WriteLine($"Final answer: {structuredJson.RootElement.GetProperty("final_answer")}"); Console.WriteLine("Reasoning steps:"); foreach (JsonElement stepElement in structuredJson.RootElement.GetProperty("steps").EnumerateArray()) { - Console.WriteLine($" - Explanation: {stepElement.GetProperty("explanation").GetString()}"); + Console.WriteLine($" - Explanation: {stepElement.GetProperty("explanation")}"); Console.WriteLine($" Output: {stepElement.GetProperty("output")}"); } } diff --git a/examples/Chat/Example06_StructuredOutputsAsync.cs b/examples/Chat/Example06_StructuredOutputsAsync.cs index 6d056b5f..47ede491 100644 --- a/examples/Chat/Example06_StructuredOutputsAsync.cs +++ b/examples/Chat/Example06_StructuredOutputsAsync.cs @@ -52,12 +52,12 @@ public async Task Example06_StructuredOutputsAsync() using JsonDocument structuredJson = JsonDocument.Parse(completion.Content[0].Text); - Console.WriteLine($"Final answer: {structuredJson.RootElement.GetProperty("final_answer").GetString()}"); + Console.WriteLine($"Final answer: {structuredJson.RootElement.GetProperty("final_answer")}"); Console.WriteLine("Reasoning steps:"); foreach (JsonElement stepElement in structuredJson.RootElement.GetProperty("steps").EnumerateArray()) { - Console.WriteLine($" - Explanation: {stepElement.GetProperty("explanation").GetString()}"); + Console.WriteLine($" - Explanation: {stepElement.GetProperty("explanation")}"); Console.WriteLine($" Output: {stepElement.GetProperty("output")}"); } }