Skip to content

Commit b08cc8b

Browse files
committed
Add a sample
1 parent 1dd0134 commit b08cc8b

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using NUnit.Framework;
2+
using OpenAI.Responses;
3+
using System;
4+
5+
namespace OpenAI.Examples;
6+
7+
// This example uses experimental APIs which are subject to change. To use experimental APIs,
8+
// please acknowledge their experimental status by suppressing the corresponding warning.
9+
#pragma warning disable OPENAI001
10+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
11+
12+
public partial class ResponseExamples
13+
{
14+
[Test]
15+
public void Example09_ModelOverridePerRequest()
16+
{
17+
OpenAIResponseClient client = new(model: "gpt-4o", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
18+
19+
// Add extra request fields using Patch.
20+
// Patch lets you set fields like `model` that aren't exposed on ResponseCreationOptions.
21+
// See the API docs https://platform.openai.com/docs/api-reference/responses/create for supported additional fields.
22+
ResponseCreationOptions options = new();
23+
options.Patch.Set("$.model"u8, "gpt-5");
24+
25+
OpenAIResponse response = client.CreateResponse("Say 'this is a test.", options);
26+
27+
Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}, [Mode]: {response.Model}");
28+
}
29+
}
30+
31+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
32+
#pragma warning restore OPENAI001
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using NUnit.Framework;
2+
using OpenAI.Responses;
3+
using System;
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 Example09_ModelOverridePerRequestAsync()
17+
{
18+
OpenAIResponseClient client = new(model: "gpt-4o", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
19+
20+
// Add extra request fields using Patch.
21+
// Patch lets you set fields like `model` that aren't exposed on ResponseCreationOptions.
22+
// See the API docs https://platform.openai.com/docs/api-reference/responses/create for supported additional fields.
23+
ResponseCreationOptions options = new();
24+
options.Patch.Set("$.model"u8, "gpt-5");
25+
26+
OpenAIResponse response = await client.CreateResponseAsync("Say 'this is a test.", options);
27+
28+
Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}, [Mode]: {response.Model}");
29+
}
30+
}
31+
32+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
33+
#pragma warning restore OPENAI001

0 commit comments

Comments
 (0)