Skip to content

Commit 08c4123

Browse files
committed
Add samples
1 parent 1e8cd92 commit 08c4123

File tree

3 files changed

+80
-7
lines changed

3 files changed

+80
-7
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using NUnit.Framework;
2+
using OpenAI.Chat;
3+
using System;
4+
using System.Collections.Generic;
5+
6+
namespace OpenAI.Examples;
7+
8+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
9+
public partial class ChatExamples
10+
{
11+
[Test]
12+
public void Example07_InputAdditionalPropertyValue()
13+
{
14+
ChatClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
15+
16+
// you can use the Patch property to set additional properties in the input
17+
ChatCompletionOptions options = new();
18+
options.Patch.Set("$.reasoning_effort"u8, "minimal");
19+
20+
List<ChatMessage> messages =
21+
[
22+
new UserChatMessage("What's the weather like today?"),
23+
];
24+
ChatCompletion completion = client.CompleteChat(messages, options);
25+
26+
Console.WriteLine($"[ASSISTANT]: {completion.Content[0].Text}");
27+
28+
// you can also read those properties back from the response
29+
var effort = completion.Patch.GetString("$.reasoning_effort"u8);
30+
Console.WriteLine($"effort={effort}");
31+
}
32+
}
33+
34+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.

examples/Responses/Example07_InputAdditionalProperties.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@ public void Example07_InputAdditionalProperties()
1616
{
1717
OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
1818

19+
// you can use the Patch property to set additional properties in the input
1920
ResponseCreationOptions options = new();
20-
options.Patch.Set("$.reasoning.effort"u8, "low");
21+
options.Patch.Set("$.reasoning.effort"u8, "high");
2122
options.Patch.Set("$.text.verbosity"u8, "medium");
2223

23-
Console.WriteLine($"JsonPatch input - {options.Patch}");
24-
OpenAIResponse response = client.CreateResponse("What is the answer to the ultimate question of life, the universe, and everything?");
24+
OpenAIResponse response = client.CreateResponse("What is the answer to the ultimate question of life, the universe, and everything?", options);
2525

2626
Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}");
27-
string effort = response.Patch.GetString("$.reasoning.effort"u8);
28-
string verbosity = response.Patch.GetString("$.text.verbosity"u8);
29-
Console.WriteLine($"effort - {effort}");
30-
Console.WriteLine($"verbosity - {verbosity}");
27+
28+
// you can also read those properties back from the response
29+
var effort = response.Patch.GetString("$.reasoning.effort"u8);
30+
var verbosity = response.Patch.GetString("$.text.verbosity"u8);
31+
Console.WriteLine($"effort={effort}, verbosity={verbosity}");
3132
}
3233
}
34+
3335
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
3436
#pragma warning restore OPENAI001
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using NUnit.Framework;
2+
using System;
3+
using OpenAI.Responses;
4+
using System.Threading.Tasks;
5+
6+
namespace OpenAI.Examples;
7+
8+
// This example uses experimental APIs which are subject to change. To use experimental APIs,
9+
// please acknowledge their experimental status by suppressing the corresponding warning.
10+
#pragma warning disable OPENAI001
11+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
12+
13+
public partial class ResponseExamples
14+
{
15+
[Test]
16+
public async Task Example07_InputAdditionalPropertiesAsync()
17+
{
18+
OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
19+
20+
// you can use the Patch property to set additional properties in the input
21+
ResponseCreationOptions options = new();
22+
options.Patch.Set("$.reasoning.effort"u8, "high");
23+
options.Patch.Set("$.text.verbosity"u8, "medium");
24+
25+
OpenAIResponse response = await client.CreateResponseAsync("What is the answer to the ultimate question of life, the universe, and everything?", options);
26+
27+
Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}");
28+
29+
// you can also read those properties back from the response
30+
var effort = response.Patch.GetString("$.reasoning.effort"u8);
31+
var verbosity = response.Patch.GetString("$.text.verbosity"u8);
32+
Console.WriteLine($"effort={effort}, verbosity={verbosity}");
33+
}
34+
}
35+
36+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
37+
#pragma warning restore OPENAI001

0 commit comments

Comments
 (0)