-
Notifications
You must be signed in to change notification settings - Fork 421
Expand file tree
/
Copy pathExample07_InputAdditionalPropertiesAsync.cs
More file actions
48 lines (39 loc) · 2.29 KB
/
Copy pathExample07_InputAdditionalPropertiesAsync.cs
File metadata and controls
48 lines (39 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using NUnit.Framework;
using OpenAI.Responses;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace OpenAI.Examples;
// This example uses experimental APIs which are subject to change. To use experimental APIs,
// please acknowledge their experimental status by suppressing the corresponding warning.
#pragma warning disable OPENAI001
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
public partial class ResponseExamples
{
[Test]
public async Task Example07_InputAdditionalPropertiesAsync()
{
ResponsesClient client = new(apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
List<ResponseItem> inputItems =
[
ResponseItem.CreateUserMessageItem("What is the answer to the ultimate question of life, the universe, and everything?"),
];
// Add extra request fields using Patch.
// Patch lets you set fields like `reasoning.effort` and `text.verbosity` that aren’t modeled on CreateResponseOptions in the request payload.
// See the API docs https://platform.openai.com/docs/api-reference/responses/create for supported additional fields.
CreateResponseOptions options = new("gpt-5", inputItems);
options.Patch.Set("$.reasoning.effort"u8, "high");
options.Patch.Set("$.text.verbosity"u8, "medium");
ResponseResult response = await client.CreateResponseAsync(options);
Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}");
// Read extra fields from the response via Patch.
// The service returns fields like `reasoning.effort` and `text.verbosity` that aren’t modeled on OpenAIResponse.
// You can access their values by using the path with Patch.
// See the API docs https://platform.openai.com/docs/api-reference/responses/object for supported additional fields.
var effort = response.Patch.GetString("$.reasoning.effort"u8);
var verbosity = response.Patch.GetString("$.text.verbosity"u8);
Console.WriteLine($"effort={effort}, verbosity={verbosity}");
}
}
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
#pragma warning restore OPENAI001