Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Release History

## 2.2.0-beta.3 (Unreleased)

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes

## 2.2.0-beta.2 (2025-02-18)

### Bugs fixed
Expand Down
682 changes: 672 additions & 10 deletions api/OpenAI.net8.0.cs

Large diffs are not rendered by default.

676 changes: 666 additions & 10 deletions api/OpenAI.netstandard2.0.cs

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions examples/Responses/Example01_CuaFlow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using NUnit.Framework;
using OpenAI.Responses;
using System;
using System.ClientModel;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace OpenAI.Examples;

#pragma warning disable OPENAICUA001

public partial class ResponsesExamples
{
[Test]
public async Task Example01_CuaFlow()
{
OpenAIResponseClient client = new(
model: "computer-use-preview",
credential: new ApiKeyCredential(Environment.GetEnvironmentVariable("OPENAI_API_KEY")));

OpenAIResponse response = await client.CreateResponseAsync(
[ResponseItem.CreateUserMessageItem("Click on the OK button")],
new ResponseCreationOptions()
{
Tools = { ResponseTool.CreateComputerTool(1024, 768, ComputerToolEnvironment.Windows) },
});

if (response.OutputItems.FirstOrDefault() is ComputerCallResponseItem computerCall)
{
if (computerCall.Action.Kind == ComputerCallActionKind.Screenshot)
{
Uri screenshotLink = new("https://uxmovement.com/wp-content/uploads/2011/05/left-to-right-mapping.png");

response = await client.CreateResponseAsync(
[ResponseItem.CreateComputerCallOutputItem(computerCall.Id, [], screenshotLink)]);
}
else if (computerCall.Action.Kind == ComputerCallActionKind.Click)
{
Console.WriteLine($"Instruction from model: click");
}
}
}
}
68 changes: 34 additions & 34 deletions src/Custom/Administration/Internal/GeneratorStubs.cs
Original file line number Diff line number Diff line change
@@ -1,36 +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 { }
[CodeGenType("AuditLogActorServiceAccount")] internal partial class InternalAuditLogActorServiceAccount { }
[CodeGenType("AuditLogActorUser")] internal partial class InternalAuditLogActorUser { }
[CodeGenType("AuditLogActorApiKey")] internal partial class InternalAuditLogActorApiKey { }
[CodeGenType("AuditLogActorSession")] internal partial class InternalAuditLogActorSession { }
[CodeGenType("AuditLogActor")] internal partial class InternalAuditLogActor { }
[CodeGenType("AuditLog")] internal partial class InternalAuditLog { }
[CodeGenType("ListAuditLogsResponse")] internal partial class InternalListAuditLogsResponse { }
[CodeGenType("Invite")] internal partial class InternalInvite { }
[CodeGenType("InviteListResponse")] internal partial class InternalInviteListResponse { }
[CodeGenType("InviteRequest")] internal partial class InternalInviteRequest { }
[CodeGenType("InviteDeleteResponse")] internal partial class InternalInviteDeleteResponse { }
[CodeGenType("User")] internal partial class InternalUser { }
[CodeGenType("UserListResponse")] internal partial class InternalUserListResponse { }
[CodeGenType("UserRoleUpdateRequest")] internal partial class InternalUserRoleUpdateRequest { }
[CodeGenType("UserDeleteResponse")] internal partial class InternalUserDeleteResponse { }
[CodeGenType("Project")] internal partial class InternalProject { }
[CodeGenType("ProjectListResponse")] internal partial class InternalProjectListResponse { }
[CodeGenType("ProjectCreateRequest")] internal partial class InternalProjectCreateRequest { }
[CodeGenType("ProjectUpdateRequest")] internal partial class InternalProjectUpdateRequest { }
[CodeGenType("DefaultProjectErrorResponse")] internal partial class InternalDefaultProjectErrorResponse { }
[CodeGenType("ProjectUser")] internal partial class InternalProjectUser { }
[CodeGenType("ProjectUserListResponse")] internal partial class InternalProjectUserListResponse { }
[CodeGenType("ProjectUserCreateRequest")] internal partial class InternalProjectUserCreateRequest { }
[CodeGenType("ProjectUserUpdateRequest")] internal partial class InternalProjectUserUpdateRequest { }
[CodeGenType("ProjectUserDeleteResponse")] internal partial class InternalProjectUserDeleteResponse { }
[CodeGenType("ProjectServiceAccount")] internal partial class InternalProjectServiceAccount { }
[CodeGenType("ProjectServiceAccountListResponse")] internal partial class InternalProjectServiceAccountListResponse { }
[CodeGenType("ProjectServiceAccountCreateRequest")] internal partial class InternalProjectServiceAccountCreateRequest { }
[CodeGenType("ProjectServiceAccountCreateResponse")] internal partial class InternalProjectServiceAccountCreateResponse { }
[CodeGenType("ProjectServiceAccountApiKey")] internal partial class InternalProjectServiceAccountApiKey { }
[CodeGenType("ProjectServiceAccountDeleteResponse")] internal partial class InternalProjectServiceAccountDeleteResponse { }
[CodeGenType("ProjectApiKey")] internal partial class InternalProjectApiKey { }
[CodeGenType("ProjectApiKeyListResponse")] internal partial class InternalProjectApiKeyListResponse { }
[CodeGenType("ProjectApiKeyDeleteResponse")] internal partial class InternalProjectApiKeyDeleteResponse { }
2 changes: 1 addition & 1 deletion src/Custom/Assistants/Assistant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace OpenAI.Assistants;

[Experimental("OPENAI001")]
[CodeGenModel("AssistantObject")]
[CodeGenType("AssistantObject")]
public partial class Assistant
{
// CUSTOM: Made internal.
Expand Down
53 changes: 28 additions & 25 deletions src/Custom/Assistants/AssistantClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace OpenAI.Assistants;

/// <summary> The service client for OpenAI assistants operations. </summary>
[Experimental("OPENAI001")]
[CodeGenClient("Assistants")]
[CodeGenSuppress("AssistantClient", typeof(ClientPipeline), typeof(ApiKeyCredential), typeof(Uri))]
[CodeGenType("Assistants")]
[CodeGenSuppress("AssistantClient", typeof(ClientPipeline), typeof(Uri))]
[CodeGenSuppress("CreateAssistantAsync", typeof(AssistantCreationOptions), typeof(CancellationToken))]
[CodeGenSuppress("CreateAssistant", typeof(AssistantCreationOptions), typeof(CancellationToken))]
[CodeGenSuppress("GetAssistantAsync", typeof(string))]
Expand All @@ -22,8 +22,8 @@ namespace OpenAI.Assistants;
[CodeGenSuppress("ModifyAssistant", typeof(string), typeof(AssistantModificationOptions))]
[CodeGenSuppress("DeleteAssistantAsync", typeof(string))]
[CodeGenSuppress("DeleteAssistant", typeof(string))]
[CodeGenSuppress("ListAssistantsAsync", typeof(int?), typeof(AssistantCollectionOrder?), typeof(string), typeof(string), typeof(CancellationToken))]
[CodeGenSuppress("ListAssistants", typeof(int?), typeof(AssistantCollectionOrder?), typeof(string), typeof(string), typeof(CancellationToken))]
[CodeGenSuppress("ListAssistantsAsync", typeof(int?), typeof(OpenAI.VectorStores.VectorStoreCollectionOrder?), typeof(string), typeof(string), typeof(CancellationToken))]
[CodeGenSuppress("ListAssistants", typeof(int?), typeof(OpenAI.VectorStores.VectorStoreCollectionOrder?), typeof(string), typeof(string), typeof(CancellationToken))]
public partial class AssistantClient
{
private readonly InternalAssistantMessageClient _messageSubClient;
Expand Down Expand Up @@ -725,11 +725,10 @@ public virtual AsyncCollectionResult<StreamingUpdate> CreateRunStreamingAsync(
options.AssistantId = assistantId;
options.Stream = true;

async Task<ClientResult> sendRequestAsync() =>
await CreateRunAsync(threadId, options, cancellationToken.ToRequestOptions(streaming: true))
.ConfigureAwait(false);

return new AsyncStreamingUpdateCollection(sendRequestAsync, cancellationToken);
return new AsyncSseUpdateCollection<StreamingUpdate>(
async () => await CreateRunAsync(threadId, options, cancellationToken.ToRequestOptions(streaming: true)).ConfigureAwait(false),
StreamingUpdate.FromSseItem,
cancellationToken);
}

/// <summary>
Expand All @@ -753,8 +752,10 @@ public virtual CollectionResult<StreamingUpdate> CreateRunStreaming(
options.AssistantId = assistantId;
options.Stream = true;

ClientResult sendRequest() => CreateRun(threadId, options, cancellationToken.ToRequestOptions(streaming: true));
return new StreamingUpdateCollection(sendRequest, cancellationToken);
return new SseUpdateCollection<StreamingUpdate>(
() => CreateRun(threadId, options, cancellationToken.ToRequestOptions(streaming: true)),
StreamingUpdate.FromSseItem,
cancellationToken);
}

/// <summary>
Expand Down Expand Up @@ -818,11 +819,10 @@ public virtual AsyncCollectionResult<StreamingUpdate> CreateThreadAndRunStreamin
runOptions.Stream = true;
BinaryContent protocolContent = CreateThreadAndRunProtocolContent(assistantId, threadOptions, runOptions);

async Task<ClientResult> sendRequestAsync() =>
await CreateThreadAndRunAsync(protocolContent, cancellationToken.ToRequestOptions(streaming: true))
.ConfigureAwait(false);

return new AsyncStreamingUpdateCollection(sendRequestAsync, cancellationToken);
return new AsyncSseUpdateCollection<StreamingUpdate>(
async () => await CreateThreadAndRunAsync(protocolContent, cancellationToken.ToRequestOptions(streaming: true)).ConfigureAwait(false),
StreamingUpdate.FromSseItem,
cancellationToken);
}

/// <summary>
Expand All @@ -844,8 +844,10 @@ public virtual CollectionResult<StreamingUpdate> CreateThreadAndRunStreaming(
runOptions.Stream = true;
BinaryContent protocolContent = CreateThreadAndRunProtocolContent(assistantId, threadOptions, runOptions);

ClientResult sendRequest() => CreateThreadAndRun(protocolContent, cancellationToken.ToRequestOptions(streaming: true));
return new StreamingUpdateCollection(sendRequest, cancellationToken);
return new SseUpdateCollection<StreamingUpdate>(
() => CreateThreadAndRun(protocolContent, cancellationToken.ToRequestOptions(streaming: true)),
StreamingUpdate.FromSseItem,
cancellationToken);
}

/// <summary>
Expand Down Expand Up @@ -1043,11 +1045,10 @@ public virtual AsyncCollectionResult<StreamingUpdate> SubmitToolOutputsToRunStre

BinaryContent content = new InternalSubmitToolOutputsRunRequest(toolOutputs.ToList(), stream: true, null);

async Task<ClientResult> sendRequestAsync() =>
await SubmitToolOutputsToRunAsync(threadId, runId, content, cancellationToken.ToRequestOptions(streaming: true))
.ConfigureAwait(false);

return new AsyncStreamingUpdateCollection(sendRequestAsync, cancellationToken);
return new AsyncSseUpdateCollection<StreamingUpdate>(
async () => await SubmitToolOutputsToRunAsync(threadId, runId, content, cancellationToken.ToRequestOptions(streaming: true)).ConfigureAwait(false),
StreamingUpdate.FromSseItem,
cancellationToken);
}

/// <summary>
Expand All @@ -1070,8 +1071,10 @@ public virtual CollectionResult<StreamingUpdate> SubmitToolOutputsToRunStreaming

BinaryContent content = new InternalSubmitToolOutputsRunRequest(toolOutputs.ToList(), stream: true, null);

ClientResult sendRequest() => SubmitToolOutputsToRun(threadId, runId, content, cancellationToken.ToRequestOptions(streaming: true));
return new StreamingUpdateCollection(sendRequest, cancellationToken);
return new SseUpdateCollection<StreamingUpdate>(
() => SubmitToolOutputsToRun(threadId, runId, content, cancellationToken.ToRequestOptions(streaming: true)),
StreamingUpdate.FromSseItem,
cancellationToken);
}

/// <summary>
Expand Down
43 changes: 33 additions & 10 deletions src/Custom/Assistants/AssistantCollectionOrder.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
using System.Diagnostics.CodeAnalysis;
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;

namespace OpenAI.Assistants;

// CUSTOM: Renamed.
[Experimental("OPENAI001")]
[CodeGenModel("ListAssistantsRequestOrder")]
public readonly partial struct AssistantCollectionOrder
public readonly partial struct AssistantCollectionOrder: IEquatable<AssistantCollectionOrder>
{
// CUSTOM: Renamed.
[CodeGenMember("Asc")]
public static AssistantCollectionOrder Ascending { get; } = new AssistantCollectionOrder(AscValue);
public static AssistantCollectionOrder Ascending { get; } = new AssistantCollectionOrder("asc");

// CUSTOM: Renamed.
[CodeGenMember("Desc")]
public static AssistantCollectionOrder Descending { get; } = new AssistantCollectionOrder(DescValue);
public static AssistantCollectionOrder Descending { get; } = new AssistantCollectionOrder("desc");

private readonly string _value;
private const string AscValue = "asc";
private const string DescValue = "desc";

public AssistantCollectionOrder(string value)
{
Argument.AssertNotNull(value, nameof(value));

_value = value;
}

public static bool operator ==(AssistantCollectionOrder left, AssistantCollectionOrder right) => left.Equals(right);

public static bool operator !=(AssistantCollectionOrder left, AssistantCollectionOrder right) => !left.Equals(right);

public static implicit operator AssistantCollectionOrder(string value) => new AssistantCollectionOrder(value);

[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => obj is AssistantCollectionOrder other && Equals(other);

public bool Equals(AssistantCollectionOrder other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase);

[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0;

public override string ToString() => _value;
}
11 changes: 5 additions & 6 deletions src/Custom/Assistants/AssistantCreationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using OpenAI.Chat;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

Expand All @@ -7,7 +8,7 @@ namespace OpenAI.Assistants;
/// Represents additional options available when creating a new <see cref="Assistant"/>.
/// </summary>
[Experimental("OPENAI001")]
[CodeGenModel("CreateAssistantRequest")]
[CodeGenType("CreateAssistantRequest")]
[CodeGenSuppress(nameof(AssistantCreationOptions), typeof(string))]
public partial class AssistantCreationOptions
{
Expand Down Expand Up @@ -39,11 +40,9 @@ public partial class AssistantCreationOptions
[CodeGenMember("TopP")]
public float? NucleusSamplingFactor { get; set; }

internal AssistantCreationOptions(InternalCreateAssistantRequestModel model)
: this()
{
Model = model.ToString();
}
// CUSTOM: Made internal.
[CodeGenMember("ReasoningEffort")]
internal ChatReasoningEffortLevel? ReasoningEffortLevel { get; set; }

/// <summary>
/// Creates a new instance of <see cref="AssistantCreationOptions"/>.
Expand Down
2 changes: 1 addition & 1 deletion src/Custom/Assistants/AssistantDeletionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace OpenAI.Assistants;

[Experimental("OPENAI001")]
[CodeGenModel("DeleteAssistantResponse")]
[CodeGenType("DeleteAssistantResponse")]
public partial class AssistantDeletionResult
{
// CUSTOM: Renamed.
Expand Down
7 changes: 6 additions & 1 deletion src/Custom/Assistants/AssistantModificationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using OpenAI.Chat;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

Expand All @@ -7,7 +8,7 @@ namespace OpenAI.Assistants;
/// Represents additional options available when modifying an existing <see cref="Assistant"/>.
/// </summary>
[Experimental("OPENAI001")]
[CodeGenModel("ModifyAssistantRequest")]
[CodeGenType("ModifyAssistantRequest")]
public partial class AssistantModificationOptions
{
/// <summary>
Expand Down Expand Up @@ -42,4 +43,8 @@ public partial class AssistantModificationOptions
/// </summary>
[CodeGenMember("TopP")]
public float? NucleusSamplingFactor { get; set; }

// CUSTOM: Made internal.
[CodeGenMember("ReasoningEffort")]
internal ChatReasoningEffortLevel? ReasoningEffortLevel { get; set; }
}
2 changes: 1 addition & 1 deletion src/Custom/Assistants/AssistantResponseFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace OpenAI.Assistants;

[Experimental("OPENAI001")]
[CodeGenModel("AssistantResponseFormat")]
[CodeGenType("AssistantResponseFormat")]
public partial class AssistantResponseFormat : IEquatable<AssistantResponseFormat>, IEquatable<string>
{
public static AssistantResponseFormat Auto { get; } = CreateAutoFormat();
Expand Down
2 changes: 1 addition & 1 deletion src/Custom/Assistants/AssistantThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace OpenAI.Assistants;

[Experimental("OPENAI001")]
[CodeGenModel("ThreadObject")]
[CodeGenType("ThreadObject")]
public partial class AssistantThread
{
// CUSTOM: Made internal.
Expand Down
2 changes: 1 addition & 1 deletion src/Custom/Assistants/CodeInterpreterToolResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace OpenAI.Assistants;

/// <summary> The AssistantObjectToolResourcesCodeInterpreter. </summary>
[Experimental("OPENAI001")]
[CodeGenModel("AssistantObjectToolResourcesCodeInterpreter")]
[CodeGenType("AssistantObjectToolResourcesCodeInterpreter")]
public partial class CodeInterpreterToolResources
{
private ChangeTrackingList<string> _fileIds = new ChangeTrackingList<string>();
Expand Down
2 changes: 1 addition & 1 deletion src/Custom/Assistants/FileSearchRankingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAI.Assistants;

[Experimental("OPENAI001")]
[CodeGenModel("FileSearchRankingOptions")]
[CodeGenType("FileSearchRankingOptions")]
[CodeGenSuppress(nameof(FileSearchRankingOptions), typeof(float))]
[CodeGenSuppress(nameof(FileSearchRankingOptions), typeof(FileSearchRankingOptions), typeof(float), typeof(IDictionary<string, BinaryData>))]
public partial class FileSearchRankingOptions
Expand Down
Loading