Skip to content

Commit b8ec620

Browse files
authored
Simplify structured outputs sample code (#236)
* Simplify structured outputs sample code * Update README sample
1 parent ef201cd commit b8ec620

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,12 @@ ChatCompletion completion = client.CompleteChat(messages, options);
342342

343343
using JsonDocument structuredJson = JsonDocument.Parse(completion.Content[0].Text);
344344

345-
Console.WriteLine($"Final answer: {structuredJson.RootElement.GetProperty("final_answer").GetString()}");
345+
Console.WriteLine($"Final answer: {structuredJson.RootElement.GetProperty("final_answer")}");
346346
Console.WriteLine("Reasoning steps:");
347347

348348
foreach (JsonElement stepElement in structuredJson.RootElement.GetProperty("steps").EnumerateArray())
349349
{
350-
Console.WriteLine($" - Explanation: {stepElement.GetProperty("explanation").GetString()}");
350+
Console.WriteLine($" - Explanation: {stepElement.GetProperty("explanation")}");
351351
Console.WriteLine($" Output: {stepElement.GetProperty("output")}");
352352
}
353353
```

examples/Chat/Example06_StructuredOutputs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ public void Example06_StructuredOutputs()
5151

5252
using JsonDocument structuredJson = JsonDocument.Parse(completion.Content[0].Text);
5353

54-
Console.WriteLine($"Final answer: {structuredJson.RootElement.GetProperty("final_answer").GetString()}");
54+
Console.WriteLine($"Final answer: {structuredJson.RootElement.GetProperty("final_answer")}");
5555
Console.WriteLine("Reasoning steps:");
5656

5757
foreach (JsonElement stepElement in structuredJson.RootElement.GetProperty("steps").EnumerateArray())
5858
{
59-
Console.WriteLine($" - Explanation: {stepElement.GetProperty("explanation").GetString()}");
59+
Console.WriteLine($" - Explanation: {stepElement.GetProperty("explanation")}");
6060
Console.WriteLine($" Output: {stepElement.GetProperty("output")}");
6161
}
6262
}

examples/Chat/Example06_StructuredOutputsAsync.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public async Task Example06_StructuredOutputsAsync()
5252

5353
using JsonDocument structuredJson = JsonDocument.Parse(completion.Content[0].Text);
5454

55-
Console.WriteLine($"Final answer: {structuredJson.RootElement.GetProperty("final_answer").GetString()}");
55+
Console.WriteLine($"Final answer: {structuredJson.RootElement.GetProperty("final_answer")}");
5656
Console.WriteLine("Reasoning steps:");
5757

5858
foreach (JsonElement stepElement in structuredJson.RootElement.GetProperty("steps").EnumerateArray())
5959
{
60-
Console.WriteLine($" - Explanation: {stepElement.GetProperty("explanation").GetString()}");
60+
Console.WriteLine($" - Explanation: {stepElement.GetProperty("explanation")}");
6161
Console.WriteLine($" Output: {stepElement.GetProperty("output")}");
6262
}
6363
}

0 commit comments

Comments
 (0)