Skip to content
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .dotnet/OpenAI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAI", "src\OpenAI.csproj
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAI.Examples", "examples\OpenAI.Examples.csproj", "{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.Tests", "tests\OpenAI.Tests.csproj", "{6F156401-2544-41D7-B204-3148C51C1D09}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAI.Tests", "tests\OpenAI.Tests.csproj", "{6F156401-2544-41D7-B204-3148C51C1D09}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.ClientModel", "..\..\azure-sdk-for-net\sdk\core\System.ClientModel\src\System.ClientModel.csproj", "{C427A4AD-EEC8-4149-8F9F-29F963F2D81A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -26,11 +28,15 @@ Global
{6F156401-2544-41D7-B204-3148C51C1D09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F156401-2544-41D7-B204-3148C51C1D09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F156401-2544-41D7-B204-3148C51C1D09}.Release|Any CPU.Build.0 = Release|Any CPU
{C427A4AD-EEC8-4149-8F9F-29F963F2D81A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C427A4AD-EEC8-4149-8F9F-29F963F2D81A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C427A4AD-EEC8-4149-8F9F-29F963F2D81A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C427A4AD-EEC8-4149-8F9F-29F963F2D81A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}
EndGlobalSection
EndGlobal
EndGlobal
27 changes: 10 additions & 17 deletions .dotnet/api/OpenAI.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,16 +1153,15 @@ public class BatchClient {
}
public class CreateBatchOperation : OperationResult {
public string BatchId { get; }
public override bool IsCompleted { get; protected set; }
public override ContinuationToken? RehydrationToken { get; protected set; }
public virtual ClientResult CancelBatch(RequestOptions? options);
public virtual Task<ClientResult> CancelBatchAsync(RequestOptions? options);
public virtual ClientResult GetBatch(RequestOptions? options);
public virtual Task<ClientResult> GetBatchAsync(RequestOptions? options);
public static CreateBatchOperation Rehydrate(BatchClient client, ContinuationToken rehydrationToken, CancellationToken cancellationToken = default);
public static Task<CreateBatchOperation> RehydrateAsync(BatchClient client, ContinuationToken rehydrationToken, CancellationToken cancellationToken = default);
public override void WaitForCompletion(CancellationToken cancellationToken = default);
public override Task WaitForCompletionAsync(CancellationToken cancellationToken = default);
public override ClientResult UpdateStatus(RequestOptions? options = null);
public override ValueTask<ClientResult> UpdateStatusAsync(RequestOptions? options = null);
}
}
namespace OpenAI.Chat {
Expand Down Expand Up @@ -1729,7 +1728,6 @@ public class OpenAIFileInfoCollection : ObjectModel.ReadOnlyCollection<OpenAIFil
}
namespace OpenAI.FineTuning {
public class CreateJobOperation : OperationResult {
public override bool IsCompleted { get; protected set; }
public string JobId { get; }
public override ContinuationToken? RehydrationToken { get; protected set; }
public virtual ClientResult CancelJob(RequestOptions? options);
Expand All @@ -1742,8 +1740,8 @@ public class CreateJobOperation : OperationResult {
public virtual Task<ClientResult> GetJobEventsAsync(string after, int? limit, RequestOptions? options);
public static CreateJobOperation Rehydrate(FineTuningClient client, ContinuationToken rehydrationToken, CancellationToken cancellationToken = default);
public static Task<CreateJobOperation> RehydrateAsync(FineTuningClient client, ContinuationToken rehydrationToken, CancellationToken cancellationToken = default);
public override void WaitForCompletion(CancellationToken cancellationToken = default);
public override Task WaitForCompletionAsync(CancellationToken cancellationToken = default);
public override ClientResult UpdateStatus(RequestOptions? options = null);
public override ValueTask<ClientResult> UpdateStatusAsync(RequestOptions? options = null);
}
public class FineTuningClient {
protected FineTuningClient();
Expand Down Expand Up @@ -2005,9 +2003,7 @@ public class ModerationResult : IJsonModel<ModerationResult>, IPersistableModel<
}
namespace OpenAI.VectorStores {
public class AddFileToVectorStoreOperation : OperationResult {
public AddFileToVectorStoreOperation(ClientPipeline pipeline, Uri endpoint, ClientResult<VectorStoreFileAssociation> result) : base(default!);
public string FileId { get; }
public override bool IsCompleted { get; protected set; }
public override ContinuationToken? RehydrationToken { get; protected set; }
public VectorStoreFileAssociationStatus? Status { get; }
public VectorStoreFileAssociation? Value { get; }
Expand All @@ -2020,12 +2016,11 @@ public class AddFileToVectorStoreOperation : OperationResult {
public virtual Task<ClientResult<VectorStoreFileAssociation>> GetFileAssociationAsync(CancellationToken cancellationToken = default);
public static AddFileToVectorStoreOperation Rehydrate(VectorStoreClient client, ContinuationToken rehydrationToken, CancellationToken cancellationToken = default);
public static Task<AddFileToVectorStoreOperation> RehydrateAsync(VectorStoreClient client, ContinuationToken rehydrationToken, CancellationToken cancellationToken = default);
public override void WaitForCompletion(CancellationToken cancellationToken = default);
public override Task WaitForCompletionAsync(CancellationToken cancellationToken = default);
public override ClientResult UpdateStatus(RequestOptions? options = null);
public override ValueTask<ClientResult> UpdateStatusAsync(RequestOptions? options = null);
}
public class CreateBatchFileJobOperation : OperationResult {
public string BatchId { get; }
public override bool IsCompleted { get; protected set; }
public override ContinuationToken? RehydrationToken { get; protected set; }
public VectorStoreBatchFileJobStatus? Status { get; }
public VectorStoreBatchFileJob? Value { get; }
Expand All @@ -2052,12 +2047,10 @@ public class CreateBatchFileJobOperation : OperationResult {
public virtual IAsyncEnumerable<ClientResult> GetFilesInBatchAsync(int? limit, string? order, string? after, string? before, string? filter, RequestOptions? options);
public static CreateBatchFileJobOperation Rehydrate(VectorStoreClient client, ContinuationToken rehydrationToken, CancellationToken cancellationToken = default);
public static Task<CreateBatchFileJobOperation> RehydrateAsync(VectorStoreClient client, ContinuationToken rehydrationToken, CancellationToken cancellationToken = default);
public override void WaitForCompletion(CancellationToken cancellationToken = default);
public override Task WaitForCompletionAsync(CancellationToken cancellationToken = default);
public override ClientResult UpdateStatus(RequestOptions? options = null);
public override ValueTask<ClientResult> UpdateStatusAsync(RequestOptions? options = null);
}
public class CreateVectorStoreOperation : OperationResult {
public CreateVectorStoreOperation(ClientPipeline pipeline, Uri endpoint, ClientResult<VectorStore> result) : base(default!);
public override bool IsCompleted { get; protected set; }
public override ContinuationToken? RehydrationToken { get; protected set; }
public VectorStoreStatus? Status { get; }
public VectorStore? Value { get; }
Expand All @@ -2070,8 +2063,8 @@ public class CreateVectorStoreOperation : OperationResult {
public virtual Task<ClientResult<VectorStore>> GetVectorStoreAsync(CancellationToken cancellationToken = default);
public static CreateVectorStoreOperation Rehydrate(VectorStoreClient client, ContinuationToken rehydrationToken, CancellationToken cancellationToken = default);
public static Task<CreateVectorStoreOperation> RehydrateAsync(VectorStoreClient client, ContinuationToken rehydrationToken, CancellationToken cancellationToken = default);
public override void WaitForCompletion(CancellationToken cancellationToken = default);
public override Task WaitForCompletionAsync(CancellationToken cancellationToken = default);
public override ClientResult UpdateStatus(RequestOptions? options = null);
public override ValueTask<ClientResult> UpdateStatusAsync(RequestOptions? options = null);
}
public abstract class FileChunkingStrategy : IJsonModel<FileChunkingStrategy>, IPersistableModel<FileChunkingStrategy> {
public static FileChunkingStrategy Auto { get; }
Expand Down
41 changes: 11 additions & 30 deletions .dotnet/src/Custom/Batch/CreateBatchOperation.Protocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public partial class CreateBatchOperation : OperationResult

private readonly string _batchId;

private PollingInterval? _pollingInterval;

internal CreateBatchOperation(
ClientPipeline pipeline,
Uri endpoint,
Expand All @@ -34,7 +32,7 @@ internal CreateBatchOperation(
_endpoint = endpoint;
_batchId = batchId;

IsCompleted = GetIsCompleted(status);
HasCompleted = GetHasCompleted(status);
RehydrationToken = new CreateBatchOperationToken(batchId);
}

Expand All @@ -43,9 +41,6 @@ internal CreateBatchOperation(
/// <inheritdoc/>
public override ContinuationToken? RehydrationToken { get; protected set; }

/// <inheritdoc/>
public override bool IsCompleted { get; protected set; }

/// <summary>
/// Recreates a <see cref="CreateBatchOperation"/> from a rehydration token.
/// </summary>
Expand Down Expand Up @@ -101,37 +96,23 @@ public static CreateBatchOperation Rehydrate(BatchClient client, ContinuationTok
}

/// <inheritdoc/>
public override async Task WaitForCompletionAsync(CancellationToken cancellationToken = default)
public override async ValueTask<ClientResult> UpdateStatusAsync(RequestOptions? options = null)
{
_pollingInterval ??= new();

while (!IsCompleted)
{
PipelineResponse response = GetRawResponse();
ClientResult result = await GetBatchAsync(options).ConfigureAwait(false);

await _pollingInterval.WaitAsync(response, cancellationToken);
ApplyUpdate(result);

ClientResult result = await GetBatchAsync(cancellationToken.ToRequestOptions()).ConfigureAwait(false);

ApplyUpdate(result);
}
return result;
}

/// <inheritdoc/>
public override void WaitForCompletion(CancellationToken cancellationToken = default)
public override ClientResult UpdateStatus(RequestOptions? options = null)
{
_pollingInterval ??= new();

while (!IsCompleted)
{
PipelineResponse response = GetRawResponse();

_pollingInterval.Wait(response, cancellationToken);
ClientResult result = GetBatch(options);

ClientResult result = GetBatch(cancellationToken.ToRequestOptions());
ApplyUpdate(result);

ApplyUpdate(result);
}
return result;
}

internal async Task<CreateBatchOperation> WaitUntilAsync(bool waitUntilCompleted, RequestOptions? options)
Expand All @@ -155,11 +136,11 @@ private void ApplyUpdate(ClientResult result)
using JsonDocument doc = JsonDocument.Parse(response.Content);
string? status = doc.RootElement.GetProperty("status"u8).GetString();

IsCompleted = GetIsCompleted(status);
HasCompleted = GetHasCompleted(status);
SetRawResponse(response);
}

private static bool GetIsCompleted(string? status)
private static bool GetHasCompleted(string? status)
{
return status == InternalBatchStatus.Completed ||
status == InternalBatchStatus.Cancelled ||
Expand Down
41 changes: 11 additions & 30 deletions .dotnet/src/Custom/FineTuning/CreateJobOperation.Protocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public partial class CreateJobOperation : OperationResult

private readonly string _jobId;

private PollingInterval? _pollingInterval;

internal CreateJobOperation(
ClientPipeline pipeline,
Uri endpoint,
Expand All @@ -32,7 +30,7 @@ internal CreateJobOperation(
_endpoint = endpoint;
_jobId = jobId;

IsCompleted = GetIsCompleted(status);
HasCompleted = GetHasCompleted(status);
RehydrationToken = new CreateJobOperationToken(jobId);
}

Expand All @@ -41,9 +39,6 @@ internal CreateJobOperation(
/// <inheritdoc/>
public override ContinuationToken? RehydrationToken { get; protected set; }

/// <inheritdoc/>
public override bool IsCompleted { get; protected set; }

/// <summary>
/// Recreates a <see cref="CreateJobOperation"/> from a rehydration token.
/// </summary>
Expand Down Expand Up @@ -99,37 +94,23 @@ public static CreateJobOperation Rehydrate(FineTuningClient client, Continuation
}

/// <inheritdoc/>
public override async Task WaitForCompletionAsync(CancellationToken cancellationToken = default)
public override async ValueTask<ClientResult> UpdateStatusAsync(RequestOptions? options = null)
{
_pollingInterval ??= new();

while (!IsCompleted)
{
PipelineResponse response = GetRawResponse();

await _pollingInterval.WaitAsync(response, cancellationToken);
ClientResult result = await GetJobAsync(options).ConfigureAwait(false);

ClientResult result = await GetJobAsync(cancellationToken.ToRequestOptions()).ConfigureAwait(false);
ApplyUpdate(result);

ApplyUpdate(result);
}
return result;
}

/// <inheritdoc/>
public override void WaitForCompletion(CancellationToken cancellationToken = default)
public override ClientResult UpdateStatus(RequestOptions? options = null)
{
_pollingInterval ??= new();

while (!IsCompleted)
{
PipelineResponse response = GetRawResponse();
ClientResult result = GetJob(options);

_pollingInterval.Wait(response, cancellationToken);
ApplyUpdate(result);

ClientResult result = GetJob(cancellationToken.ToRequestOptions());

ApplyUpdate(result);
}
return result;
}

internal async Task<CreateJobOperation> WaitUntilAsync(bool waitUntilCompleted, RequestOptions? options)
Expand All @@ -153,11 +134,11 @@ private void ApplyUpdate(ClientResult result)
using JsonDocument doc = JsonDocument.Parse(response.Content);
string? status = doc.RootElement.GetProperty("status"u8).GetString();

IsCompleted = GetIsCompleted(status);
HasCompleted = GetHasCompleted(status);
SetRawResponse(response);
}

private static bool GetIsCompleted(string? status)
private static bool GetHasCompleted(string? status)
{
return status == InternalFineTuningJobStatus.Succeeded ||
status == InternalFineTuningJobStatus.Failed ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ public partial class AddFileToVectorStoreOperation : OperationResult
private readonly string _vectorStoreId;
private readonly string _fileId;

private PollingInterval? _pollingInterval;

/// <inheritdoc/>
public override ContinuationToken? RehydrationToken { get; protected set; }

/// <inheritdoc/>
public override bool IsCompleted { get; protected set; }

/// <summary>
/// [Protocol Method] Retrieves a vector store file.
/// </summary>
Expand Down
49 changes: 21 additions & 28 deletions .dotnet/src/Custom/VectorStores/AddFileToVectorStoreOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace OpenAI.VectorStores;
[Experimental("OPENAI001")]
public partial class AddFileToVectorStoreOperation : OperationResult
{
public AddFileToVectorStoreOperation(
internal AddFileToVectorStoreOperation(
ClientPipeline pipeline,
Uri endpoint,
ClientResult<VectorStoreFileAssociation> result)
Expand All @@ -27,7 +27,7 @@ public AddFileToVectorStoreOperation(
_vectorStoreId = Value.VectorStoreId;
_fileId = Value.FileId;

IsCompleted = GetIsCompleted(Value.Status);
HasCompleted = GetHasCompleted(Value.Status);
RehydrationToken = new AddFileToVectorStoreOperationToken(VectorStoreId, FileId);
}

Expand Down Expand Up @@ -102,36 +102,29 @@ public static AddFileToVectorStoreOperation Rehydrate(VectorStoreClient client,
}

/// <inheritdoc/>
public override async Task WaitForCompletionAsync(CancellationToken cancellationToken = default)
public override async ValueTask<ClientResult> UpdateStatusAsync(RequestOptions? options = null)
{
_pollingInterval ??= new();
ClientResult result = await GetFileAssociationAsync(options).ConfigureAwait(false);

while (!IsCompleted)
{
PipelineResponse response = GetRawResponse();

await _pollingInterval.WaitAsync(response, cancellationToken);
PipelineResponse response = result.GetRawResponse();
VectorStoreFileAssociation value = VectorStoreFileAssociation.FromResponse(response);

ClientResult<VectorStoreFileAssociation> result = await GetFileAssociationAsync(cancellationToken).ConfigureAwait(false);
ApplyUpdate(response, value);

ApplyUpdate(result);
}
return result;
}

public override void WaitForCompletion(CancellationToken cancellationToken = default)
/// <inheritdoc/>
public override ClientResult UpdateStatus(RequestOptions? options = null)
{
_pollingInterval ??= new();
ClientResult result = GetFileAssociation(options);

while (!IsCompleted)
{
PipelineResponse response = GetRawResponse();

_pollingInterval.Wait(response, cancellationToken);
PipelineResponse response = result.GetRawResponse();
VectorStoreFileAssociation value = VectorStoreFileAssociation.FromResponse(response);

ClientResult<VectorStoreFileAssociation> result = GetFileAssociation(cancellationToken);
ApplyUpdate(response, value);

ApplyUpdate(result);
}
return result;
}

internal async Task<AddFileToVectorStoreOperation> WaitUntilAsync(bool waitUntilCompleted, RequestOptions? options)
Expand All @@ -148,16 +141,16 @@ internal AddFileToVectorStoreOperation WaitUntil(bool waitUntilCompleted, Reques
return this;
}

private void ApplyUpdate(ClientResult<VectorStoreFileAssociation> update)
private void ApplyUpdate(PipelineResponse response, VectorStoreFileAssociation value)
{
Value = update;
Status = Value.Status;
Value = value;
Status = value.Status;

IsCompleted = GetIsCompleted(Value.Status);
SetRawResponse(update.GetRawResponse());
HasCompleted = GetHasCompleted(value.Status);
SetRawResponse(response);
}

private static bool GetIsCompleted(VectorStoreFileAssociationStatus status)
private static bool GetHasCompleted(VectorStoreFileAssociationStatus status)
{
return status == VectorStoreFileAssociationStatus.Completed ||
status == VectorStoreFileAssociationStatus.Cancelled ||
Expand Down
Loading