-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
185 changed files
with
6,264 additions
and
1,980 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using NUnit.Framework; | ||
using OpenAI.Chat; | ||
using System; | ||
using System.Text.Json; | ||
|
||
namespace OpenAI.Examples; | ||
|
||
public partial class ChatExamples | ||
{ | ||
[Test] | ||
public void Example07_StructuredOutputs() | ||
{ | ||
ChatClient client = new("gpt-4o-mini", Environment.GetEnvironmentVariable("OPENAI_API_KEY")); | ||
|
||
ChatCompletionOptions options = new() | ||
{ | ||
ResponseFormat = ChatResponseFormat.CreateJsonSchemaFormat( | ||
name: "math_reasoning", | ||
jsonSchema: BinaryData.FromString(""" | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"steps": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"explanation": { "type": "string" }, | ||
"output": { "type": "string" } | ||
}, | ||
"required": ["explanation", "output"], | ||
"additionalProperties": false | ||
} | ||
}, | ||
"final_answer": { "type": "string" } | ||
}, | ||
"required": ["steps", "final_answer"], | ||
"additionalProperties": false | ||
} | ||
"""), | ||
strictSchemaEnabled: true) | ||
}; | ||
|
||
ChatCompletion chatCompletion = client.CompleteChat( | ||
["How can I solve 8x + 7 = -23?"], | ||
options); | ||
|
||
using JsonDocument structuredJson = JsonDocument.Parse(chatCompletion.ToString()); | ||
|
||
Console.WriteLine($"Final answer: {structuredJson.RootElement.GetProperty("final_answer").GetString()}"); | ||
Console.WriteLine("Reasoning steps:"); | ||
|
||
foreach (JsonElement stepElement in structuredJson.RootElement.GetProperty("steps").EnumerateArray()) | ||
{ | ||
Console.WriteLine($" - Explanation: {stepElement.GetProperty("explanation").GetString()}"); | ||
Console.WriteLine($" Output: {stepElement.GetProperty("output")}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using NUnit.Framework; | ||
using OpenAI.Chat; | ||
using System; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenAI.Examples; | ||
|
||
public partial class ChatExamples | ||
{ | ||
[Test] | ||
public async Task Example07_StructuredOutputsAsync() | ||
{ | ||
ChatClient client = new("gpt-4o-mini", Environment.GetEnvironmentVariable("OPENAI_API_KEY")); | ||
|
||
ChatCompletionOptions options = new() | ||
{ | ||
ResponseFormat = ChatResponseFormat.CreateJsonSchemaFormat( | ||
name: "math_reasoning", | ||
jsonSchema: BinaryData.FromString(""" | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"steps": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"explanation": { "type": "string" }, | ||
"output": { "type": "string" } | ||
}, | ||
"required": ["explanation", "output"], | ||
"additionalProperties": false | ||
} | ||
}, | ||
"final_answer": { "type": "string" } | ||
}, | ||
"required": ["steps", "final_answer"], | ||
"additionalProperties": false | ||
} | ||
"""), | ||
strictSchemaEnabled: true) | ||
}; | ||
|
||
ChatCompletion chatCompletion = await client.CompleteChatAsync( | ||
["How can I solve 8x + 7 = -23?"], | ||
options); | ||
|
||
using JsonDocument structuredJson = JsonDocument.Parse(chatCompletion.ToString()); | ||
|
||
Console.WriteLine($"Final answer: {structuredJson.RootElement.GetProperty("final_answer").GetString()}"); | ||
Console.WriteLine("Reasoning steps:"); | ||
|
||
foreach (JsonElement stepElement in structuredJson.RootElement.GetProperty("steps").EnumerateArray()) | ||
{ | ||
Console.WriteLine($" - Explanation: {stepElement.GetProperty("explanation").GetString()}"); | ||
Console.WriteLine($" Output: {stepElement.GetProperty("output")}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
namespace OpenAI.Administration; | ||
|
||
[CodeGenModel("AuditLogActorServiceAccount")] internal partial class InternalAuditLogActorServiceAccount { } | ||
[CodeGenModel("AuditLogActorUser")] internal partial class InternalAuditLogActorUser { } | ||
[CodeGenModel("AuditLogActorApiKey")] internal partial class InternalAuditLogActorApiKey { } | ||
[CodeGenModel("AuditLogActorSession")] internal partial class InternalAuditLogActorSession { } | ||
[CodeGenModel("AuditLogActor")] internal partial class InternalAuditLogActor { } | ||
[CodeGenModel("AuditLog")] internal partial class InternalAuditLog { } | ||
[CodeGenModel("ListAuditLogsResponse")] internal partial class InternalListAuditLogsResponse { } | ||
[CodeGenModel("Invite")] internal partial class InternalInvite { } | ||
[CodeGenModel("InviteListResponse")] internal partial class InternalInviteListResponse { } | ||
[CodeGenModel("InviteRequest")] internal partial class InternalInviteRequest { } | ||
[CodeGenModel("InviteDeleteResponse")] internal partial class InternalInviteDeleteResponse { } | ||
[CodeGenModel("User")] internal partial class InternalUser { } | ||
[CodeGenModel("UserListResponse")] internal partial class InternalUserListResponse { } | ||
[CodeGenModel("UserRoleUpdateRequest")] internal partial class InternalUserRoleUpdateRequest { } | ||
[CodeGenModel("UserDeleteResponse")] internal partial class InternalUserDeleteResponse { } | ||
[CodeGenModel("Project")] internal partial class InternalProject { } | ||
[CodeGenModel("ProjectListResponse")] internal partial class InternalProjectListResponse { } | ||
[CodeGenModel("ProjectCreateRequest")] internal partial class InternalProjectCreateRequest { } | ||
[CodeGenModel("ProjectUpdateRequest")] internal partial class InternalProjectUpdateRequest { } | ||
[CodeGenModel("DefaultProjectErrorResponse")] internal partial class InternalDefaultProjectErrorResponse { } | ||
[CodeGenModel("ProjectUser")] internal partial class InternalProjectUser { } | ||
[CodeGenModel("ProjectUserListResponse")] internal partial class InternalProjectUserListResponse { } | ||
[CodeGenModel("ProjectUserCreateRequest")] internal partial class InternalProjectUserCreateRequest { } | ||
[CodeGenModel("ProjectUserUpdateRequest")] internal partial class InternalProjectUserUpdateRequest { } | ||
[CodeGenModel("ProjectUserDeleteResponse")] internal partial class InternalProjectUserDeleteResponse { } | ||
[CodeGenModel("ProjectServiceAccount")] internal partial class InternalProjectServiceAccount { } | ||
[CodeGenModel("ProjectServiceAccountListResponse")] internal partial class InternalProjectServiceAccountListResponse { } | ||
[CodeGenModel("ProjectServiceAccountCreateRequest")] internal partial class InternalProjectServiceAccountCreateRequest { } | ||
[CodeGenModel("ProjectServiceAccountCreateResponse")] internal partial class InternalProjectServiceAccountCreateResponse { } | ||
[CodeGenModel("ProjectServiceAccountApiKey")] internal partial class InternalProjectServiceAccountApiKey { } | ||
[CodeGenModel("ProjectServiceAccountDeleteResponse")] internal partial class InternalProjectServiceAccountDeleteResponse { } | ||
[CodeGenModel("ProjectApiKey")] internal partial class InternalProjectApiKey { } | ||
[CodeGenModel("ProjectApiKeyListResponse")] internal partial class InternalProjectApiKeyListResponse { } | ||
[CodeGenModel("ProjectApiKeyDeleteResponse")] internal partial class InternalProjectApiKeyDeleteResponse { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.