From 253d466cd5a727a05ec4327f21eb1c8db2022735 Mon Sep 17 00:00:00 2001 From: Anne Thompson Date: Thu, 14 Mar 2024 17:24:43 -0700 Subject: [PATCH 01/18] readme --- readme.md | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/readme.md b/readme.md index c4dd93188..04bcd9be3 100644 --- a/readme.md +++ b/readme.md @@ -1,15 +1,3 @@ -A conversion of the OpenAI OpenAPI to TypeSpec. +# OpenAPI spec for the OpenAI API -There are some deltas: - -### Changes to API Semantics: - -- Many things are missing defaults (mostly due to bug where we can't set null defaults) -- Error responses have been added. -- Where known, the `object` property's type is narrowed from string to the constant value it will always be - -### Changes to API metadata or OpenAPI format - -- Much of the x-oaiMeta entries have not been added. -- In some cases, new schemas needed to be defined in order to be defined in TypeSpec (e.g. because the constraints could not be added to a model property with a heterogeneous type) -- There is presently no way to set `title` +This repository contains an [OpenAPI](https://www.openapis.org/) specification for the [OpenAI API](https://platform.openai.com/docs/api-reference). From 1495d701261a4f1b62bdd67cf4aeae3cd03730c8 Mon Sep 17 00:00:00 2001 From: Chris Schraer Date: Fri, 6 Sep 2024 13:47:07 -0700 Subject: [PATCH 02/18] completed batch and fine tuning LRO and subclient pattern updates --- .../Custom/Batch/AzureBatchClient.Protocol.cs | 78 +++------ .../src/Custom/Batch/AzureBatchClient.cs | 41 +++++ .../AzureCreateBatchOperation.Protocol.cs | 56 ++++++ .../AzureCreateJobOperation.Protocol.cs | 95 +++++++++++ .../AzureFineTuningClient.Protocol.cs | 160 ------------------ .../FineTuning/AzureFineTuningClient.cs | 36 +++- .../Batch/CreateBatchOperation.Protocol.cs | 8 +- .../FineTuning/CreateJobOperation.Protocol.cs | 10 +- .../FineTuning/FineTuningClient.Protocol.cs | 24 +-- .dotnet/src/Generated/BatchClient.cs | 13 +- .dotnet/src/Generated/FineTuningClient.cs | 78 +-------- 11 files changed, 286 insertions(+), 313 deletions(-) create mode 100644 .dotnet.azure/src/Custom/Batch/AzureCreateBatchOperation.Protocol.cs create mode 100644 .dotnet.azure/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs diff --git a/.dotnet.azure/src/Custom/Batch/AzureBatchClient.Protocol.cs b/.dotnet.azure/src/Custom/Batch/AzureBatchClient.Protocol.cs index 15d78fc00..2bedbedd8 100644 --- a/.dotnet.azure/src/Custom/Batch/AzureBatchClient.Protocol.cs +++ b/.dotnet.azure/src/Custom/Batch/AzureBatchClient.Protocol.cs @@ -3,26 +3,41 @@ using System.ClientModel; using System.ClientModel.Primitives; +using System.Text.Json; using OpenAI.Batch; namespace Azure.AI.OpenAI.Batch; internal partial class AzureBatchClient : BatchClient { - public override async Task CreateBatchAsync(BinaryContent content, RequestOptions options = null) + public override async Task CreateBatchAsync(BinaryContent content, bool waitUntilCompleted, RequestOptions options = null) { Argument.AssertNotNull(content, nameof(content)); using PipelineMessage message = CreateCreateBatchRequest(content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + PipelineResponse response = await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); + + using JsonDocument doc = JsonDocument.Parse(response.Content); + string batchId = doc.RootElement.GetProperty("id"u8).GetString(); + string status = doc.RootElement.GetProperty("status"u8).GetString(); + + CreateBatchOperation operation = new(Pipeline, _endpoint, batchId, status, response); + return await operation.WaitUntilAsync(waitUntilCompleted, options).ConfigureAwait(false); } - public override ClientResult CreateBatch(BinaryContent content, RequestOptions options = null) + public override CreateBatchOperation CreateBatch(BinaryContent content, bool waitUntilCompleted, RequestOptions options = null) { Argument.AssertNotNull(content, nameof(content)); using PipelineMessage message = CreateCreateBatchRequest(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + PipelineResponse response = Pipeline.ProcessMessage(message, options); + + using JsonDocument doc = JsonDocument.Parse(response.Content); + string batchId = doc.RootElement.GetProperty("id"u8).GetString(); + string status = doc.RootElement.GetProperty("status"u8).GetString(); + + CreateBatchOperation operation = new(Pipeline, _endpoint, batchId, status, response); + return operation.WaitUntil(waitUntilCompleted, options); } public override async Task GetBatchesAsync(string after, int? limit, RequestOptions options) @@ -37,7 +52,7 @@ public override ClientResult GetBatches(string after, int? limit, RequestOptions return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } - public override async Task GetBatchAsync(string batchId, RequestOptions options) + internal override async Task GetBatchAsync(string batchId, RequestOptions options) { Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); @@ -45,62 +60,11 @@ public override async Task GetBatchAsync(string batchId, RequestOp return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } - public override ClientResult GetBatch(string batchId, RequestOptions options) + internal override ClientResult GetBatch(string batchId, RequestOptions options) { Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); using PipelineMessage message = CreateRetrieveBatchRequest(batchId, options); return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } - - public override async Task CancelBatchAsync(string batchId, RequestOptions options) - { - Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); - - using PipelineMessage message = CreateCancelBatchRequest(batchId, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - - public override ClientResult CancelBatch(string batchId, RequestOptions options) - { - Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); - - using PipelineMessage message = CreateCancelBatchRequest(batchId, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - - private new PipelineMessage CreateCreateBatchRequest(BinaryContent content, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) - .WithMethod("POST") - .WithPath("batches") - .WithContent(content, "application/json") - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - private new PipelineMessage CreateGetBatchesRequest(string after, int? limit, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) - .WithMethod("GET") - .WithPath("batches") - .WithOptionalQueryParameter("after", after) - .WithOptionalQueryParameter("limit", limit) - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - private new PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) - .WithMethod("GET") - .WithPath("batches", batchId) - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - private new PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) - .WithMethod("POST") - .WithPath("batches", batchId, "cancel") - .WithAccept("application/json") - .WithOptions(options) - .Build(); } diff --git a/.dotnet.azure/src/Custom/Batch/AzureBatchClient.cs b/.dotnet.azure/src/Custom/Batch/AzureBatchClient.cs index 56058a27e..02a1d9502 100644 --- a/.dotnet.azure/src/Custom/Batch/AzureBatchClient.cs +++ b/.dotnet.azure/src/Custom/Batch/AzureBatchClient.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System.ClientModel; using System.ClientModel.Primitives; using OpenAI.Batch; @@ -34,4 +35,44 @@ internal AzureBatchClient( protected AzureBatchClient() { } + + internal override CreateBatchOperation CreateBatchOperation(string batchId, string status, PipelineResponse response) + { + return new AzureCreateBatchOperation(Pipeline, _endpoint, batchId, status, response, _deploymentName, _apiVersion); + } + + internal override PipelineMessage CreateCreateBatchRequest(BinaryContent content, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) + .WithMethod("POST") + .WithPath("batches") + .WithContent(content, "application/json") + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateGetBatchesRequest(string after, int? limit, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) + .WithMethod("GET") + .WithPath("batches") + .WithOptionalQueryParameter("after", after) + .WithOptionalQueryParameter("limit", limit) + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) + .WithMethod("GET") + .WithPath("batches", batchId) + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) + .WithMethod("POST") + .WithPath("batches", batchId, "cancel") + .WithAccept("application/json") + .WithOptions(options) + .Build(); } diff --git a/.dotnet.azure/src/Custom/Batch/AzureCreateBatchOperation.Protocol.cs b/.dotnet.azure/src/Custom/Batch/AzureCreateBatchOperation.Protocol.cs new file mode 100644 index 000000000..8dff3182b --- /dev/null +++ b/.dotnet.azure/src/Custom/Batch/AzureCreateBatchOperation.Protocol.cs @@ -0,0 +1,56 @@ +using System.ClientModel; +using System.ClientModel.Primitives; + +#nullable enable + +namespace Azure.AI.OpenAI.Batch; + +/// +/// A long-running operation for executing a batch from an uploaded file of +/// requests. +/// +public partial class AzureCreateBatchOperation : CreateBatchOperation +{ + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _batchId; + + private readonly string _deploymentName; + private readonly string _apiVersion; + + internal AzureCreateBatchOperation( + ClientPipeline pipeline, + Uri endpoint, + string batchId, + string status, + PipelineResponse response, + string deploymentName, + string apiVersion) + : base(pipeline, endpoint, batchId, status, response) + { + _pipeline = pipeline; + _endpoint = endpoint; + _batchId = batchId; + _deploymentName = deploymentName; + _apiVersion = apiVersion; + } + + internal override PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions? options) + => new AzureOpenAIPipelineMessageBuilder(_pipeline, _endpoint, _apiVersion, _deploymentName) + .WithMethod("GET") + .WithPath("batches", batchId) + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions? options) + => new AzureOpenAIPipelineMessageBuilder(_pipeline, _endpoint, _apiVersion, _deploymentName) + .WithMethod("POST") + .WithPath("batches", batchId, "cancel") + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + private static PipelineMessageClassifier? _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); +} \ No newline at end of file diff --git a/.dotnet.azure/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs b/.dotnet.azure/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs new file mode 100644 index 000000000..8231b5f7a --- /dev/null +++ b/.dotnet.azure/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs @@ -0,0 +1,95 @@ +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Diagnostics.CodeAnalysis; + +#nullable enable + +namespace Azure.AI.OpenAI.Custom.FineTuning; + +/// +/// A long-running operation for creating a new model from a given dataset. +/// +public partial class AzureCreateJobOperation : CreateJobOperation +{ + private readonly PipelineMessageClassifier DeleteJobClassifier = PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _jobId; + + private readonly string _apiVersion; + + internal AzureCreateJobOperation( + ClientPipeline pipeline, + Uri endpoint, + string jobId, + string status, + PipelineResponse response, + string apiVersion) + : base(pipeline, endpoint, jobId, status, response) + { + _pipeline = pipeline; + _endpoint = endpoint; + _jobId = jobId; + _apiVersion = apiVersion; + } + + [Experimental("AOAI001")] + public virtual ClientResult DeleteJob(string fineTuningJobId, RequestOptions? options) + { + using PipelineMessage message = CreateDeleteJobRequestMessage(fineTuningJobId, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + [Experimental("AOAI001")] + public virtual async Task DeleteJobAsync(string fineTuningJobId, RequestOptions? options) + { + using PipelineMessage message = CreateDeleteJobRequestMessage(fineTuningJobId, options); + PipelineResponse response = await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); + return ClientResult.FromResponse(response); + } + + private PipelineMessage CreateDeleteJobRequestMessage(string fineTuningJobId, RequestOptions? options) + => new AzureOpenAIPipelineMessageBuilder(_pipeline, _endpoint, _apiVersion) + .WithMethod("DELETE") + .WithPath("fine_tuning", "jobs", fineTuningJobId) + .WithAccept("application/json") + .WithClassifier(DeleteJobClassifier) + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateRetrieveFineTuningJobRequest(string fineTuningJobId, RequestOptions? options) + => new AzureOpenAIPipelineMessageBuilder(_pipeline, _endpoint, _apiVersion) + .WithMethod("GET") + .WithPath("fine_tuning", "jobs", fineTuningJobId) + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateCancelFineTuningJobRequest(string fineTuningJobId, RequestOptions? options) + => new AzureOpenAIPipelineMessageBuilder(_pipeline, _endpoint, _apiVersion) + .WithMethod("POST") + .WithPath("fine_tuning", "jobs", fineTuningJobId, "cancel") + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateGetFineTuningJobCheckpointsRequest(string fineTuningJobId, string after, int? limit, RequestOptions? options) + => new AzureOpenAIPipelineMessageBuilder(_pipeline, _endpoint, _apiVersion) + .WithMethod("GET") + .WithPath("fine_tuning", "jobs", fineTuningJobId, "checkpoints") + .WithOptionalQueryParameter("after", after) + .WithOptionalQueryParameter("limit", limit) + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateGetFineTuningEventsRequest(string fineTuningJobId, string after, int? limit, RequestOptions? options) + => new AzureOpenAIPipelineMessageBuilder(_pipeline, _endpoint, _apiVersion) + .WithMethod("GET") + .WithPath("fine_tuning", "jobs", fineTuningJobId, "events") + .WithOptionalQueryParameter("after", after) + .WithOptionalQueryParameter("limit", limit) + .WithAccept("application/json") + .WithOptions(options) + .Build(); +} \ No newline at end of file diff --git a/.dotnet.azure/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs b/.dotnet.azure/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs index 6c8c29537..62985c14e 100644 --- a/.dotnet.azure/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs +++ b/.dotnet.azure/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs @@ -3,169 +3,9 @@ using System.ClientModel; using System.ClientModel.Primitives; -using System.Diagnostics.CodeAnalysis; -using OpenAI.FineTuning; namespace Azure.AI.OpenAI.FineTuning; internal partial class AzureFineTuningClient : FineTuningClient { - private readonly PipelineMessageClassifier DeleteJobClassifier = PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); - - public override ClientResult CreateJob(BinaryContent content, RequestOptions options = null) - { - using PipelineMessage message = CreateCreateJobRequestMessage(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - - public override async Task CreateJobAsync(BinaryContent content, RequestOptions options = null) - { - using PipelineMessage message = CreateCreateJobRequestMessage(content, options); - PipelineResponse response = await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); - return ClientResult.FromResponse(response); - } - - public override ClientResult GetJob(string fineTuningJobId, RequestOptions options) - { - using PipelineMessage message = CreateGetJobRequestMessage(fineTuningJobId, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - - public override async Task GetJobAsync(string fineTuningJobId, RequestOptions options) - { - using PipelineMessage message = CreateGetJobRequestMessage(fineTuningJobId, options); - PipelineResponse response = await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); - return ClientResult.FromResponse(response); - } - - public override ClientResult GetJobs(string after, int? limit, RequestOptions options) - { - using PipelineMessage message = CreateGetJobsRequestMessage(after, limit, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - - public override async Task GetJobsAsync(string after, int? limit, RequestOptions options) - { - using PipelineMessage message = CreateGetJobsRequestMessage(after, limit, options); - PipelineResponse response = await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); - return ClientResult.FromResponse(response); - } - - public override ClientResult GetJobEvents(string fineTuningJobId, string after, int? limit, RequestOptions options) - { - using PipelineMessage message = CreateGetJobEventsRequestMessage(fineTuningJobId, after, limit, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - - public override async Task GetJobEventsAsync(string fineTuningJobId, string after, int? limit, RequestOptions options) - { - using PipelineMessage message = CreateGetJobEventsRequestMessage(fineTuningJobId, after, limit, options); - PipelineResponse response = await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); - return ClientResult.FromResponse(response); - } - - public override ClientResult GetJobCheckpoints(string fineTuningJobId, string after, int? limit, RequestOptions options) - { - using PipelineMessage message = CreateGetJobCheckpointsRequestMessage(fineTuningJobId, after, limit, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - - public override async Task GetJobCheckpointsAsync(string fineTuningJobId, string after, int? limit, RequestOptions options) - { - using PipelineMessage message = CreateGetJobCheckpointsRequestMessage(fineTuningJobId, after, limit, options); - PipelineResponse response = await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); - return ClientResult.FromResponse(response); - } - - public override ClientResult CancelJob(string fineTuningJobId, RequestOptions options) - { - using PipelineMessage message = CreateCancelJobRequestMessage(fineTuningJobId, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - - public override async Task CancelJobAsync(string fineTuningJobId, RequestOptions options) - { - using PipelineMessage message = CreateCancelJobRequestMessage(fineTuningJobId, options); - PipelineResponse response = await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); - return ClientResult.FromResponse(response); - } - - [Experimental("AOAI001")] - public virtual ClientResult DeleteJob(string jobId, RequestOptions options = null) - { - using PipelineMessage message = CreateDeleteJobRequestMessage(jobId, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - - [Experimental("AOAI001")] - public virtual async Task DeleteJobAsync(string jobId, RequestOptions options = null) - { - using PipelineMessage message = CreateDeleteJobRequestMessage(jobId, options); - PipelineResponse response = await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); - return ClientResult.FromResponse(response); - } - - private PipelineMessage CreateCreateJobRequestMessage(BinaryContent content, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("POST") - .WithPath("fine_tuning", "jobs") - .WithContent(content, "application/json") - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - private PipelineMessage CreateGetJobsRequestMessage(string after, int? limit, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("GET") - .WithPath("fine_tuning", "jobs") - .WithOptionalQueryParameter("after", after) - .WithOptionalQueryParameter("limit", limit) - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - private PipelineMessage CreateGetJobRequestMessage(string jobId, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("GET") - .WithPath("fine_tuning", "jobs", jobId) - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - private PipelineMessage CreateGetJobEventsRequestMessage(string jobId, string after, int? limit, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("GET") - .WithPath("fine_tuning", "jobs", jobId, "events") - .WithOptionalQueryParameter("after", after) - .WithOptionalQueryParameter("limit", limit) - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - private PipelineMessage CreateGetJobCheckpointsRequestMessage(string jobId, string after, int? limit, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("GET") - .WithPath("fine_tuning", "jobs", jobId, "checkpoints") - .WithOptionalQueryParameter("after", after) - .WithOptionalQueryParameter("limit", limit) - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - private PipelineMessage CreateCancelJobRequestMessage(string jobId, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("POST") - .WithPath("fine_tuning", "jobs", jobId, "cancel") - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - private PipelineMessage CreateDeleteJobRequestMessage(string jobId, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("DELETE") - .WithPath("fine_tuning", "jobs", jobId) - .WithAccept("application/json") - .WithClassifier(DeleteJobClassifier) - .WithOptions(options) - .Build(); } diff --git a/.dotnet.azure/src/Custom/FineTuning/AzureFineTuningClient.cs b/.dotnet.azure/src/Custom/FineTuning/AzureFineTuningClient.cs index 2b3c0f1d6..9f4c7ff1c 100644 --- a/.dotnet.azure/src/Custom/FineTuning/AzureFineTuningClient.cs +++ b/.dotnet.azure/src/Custom/FineTuning/AzureFineTuningClient.cs @@ -1,7 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using Azure.AI.OpenAI.Custom.FineTuning; using OpenAI.FineTuning; +using System.ClientModel; using System.ClientModel.Primitives; namespace Azure.AI.OpenAI.FineTuning; @@ -29,5 +31,37 @@ internal AzureFineTuningClient( } protected AzureFineTuningClient() - { } + { } + + internal override CreateJobOperation CreateJobOperation(string jobId, string status, PipelineResponse response) + { + return new AzureCreateJobOperation(Pipeline, _endpoint, jobId, status, response, _apiVersion); + } + + internal override PipelineMessage CreateCreateFineTuningJobRequest(BinaryContent content, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) + .WithMethod("POST") + .WithPath("fine_tuning", "jobs") + .WithContent(content, "application/json") + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateGetPaginatedFineTuningJobsRequest(string after, int? limit, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) + .WithMethod("GET") + .WithPath("fine_tuning", "jobs") + .WithOptionalQueryParameter("after", after) + .WithOptionalQueryParameter("limit", limit) + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateRetrieveFineTuningJobRequest(string fineTuningJobId, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) + .WithMethod("GET") + .WithPath("fine_tuning", "jobs", fineTuningJobId) + .WithAccept("application/json") + .WithOptions(options) + .Build(); } diff --git a/.dotnet/src/Custom/Batch/CreateBatchOperation.Protocol.cs b/.dotnet/src/Custom/Batch/CreateBatchOperation.Protocol.cs index 6d75ad06a..b626f1a08 100644 --- a/.dotnet/src/Custom/Batch/CreateBatchOperation.Protocol.cs +++ b/.dotnet/src/Custom/Batch/CreateBatchOperation.Protocol.cs @@ -65,7 +65,7 @@ public static async Task RehydrateAsync(BatchClient client using JsonDocument doc = JsonDocument.Parse(response.Content); string status = doc.RootElement.GetProperty("status"u8).GetString()!; - return new CreateBatchOperation(client.Pipeline, client.Endpoint, token.BatchId, status, response); + return client.CreateBatchOperation(token.BatchId, status, response); } /// @@ -92,7 +92,7 @@ public static CreateBatchOperation Rehydrate(BatchClient client, ContinuationTok using JsonDocument doc = JsonDocument.Parse(response.Content); string status = doc.RootElement.GetProperty("status"u8).GetString()!; - return new CreateBatchOperation(client.Pipeline, client.Endpoint, token.BatchId, status, response); + return client.CreateBatchOperation(token.BatchId, status, response); } /// @@ -198,7 +198,7 @@ public virtual ClientResult Cancel(RequestOptions? options) return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); } - internal PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions? options) + internal virtual PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions? options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; @@ -214,7 +214,7 @@ internal PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptio return message; } - internal PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions? options) + internal virtual PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions? options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; diff --git a/.dotnet/src/Custom/FineTuning/CreateJobOperation.Protocol.cs b/.dotnet/src/Custom/FineTuning/CreateJobOperation.Protocol.cs index ac7cc7856..6ecb5cb9e 100644 --- a/.dotnet/src/Custom/FineTuning/CreateJobOperation.Protocol.cs +++ b/.dotnet/src/Custom/FineTuning/CreateJobOperation.Protocol.cs @@ -90,7 +90,7 @@ public static CreateJobOperation Rehydrate(FineTuningClient client, Continuation using JsonDocument doc = JsonDocument.Parse(response.Content); string status = doc.RootElement.GetProperty("status"u8).GetString()!; - return new CreateJobOperation(client.Pipeline, client.Endpoint, token.JobId, status, response); + return client.CreateJobOperation(token.JobId, status, response); } /// @@ -273,7 +273,7 @@ public virtual ClientResult GetJobCheckpoints(string after, int? limit, RequestO return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); } - internal PipelineMessage CreateRetrieveFineTuningJobRequest(string fineTuningJobId, RequestOptions? options) + internal virtual PipelineMessage CreateRetrieveFineTuningJobRequest(string fineTuningJobId, RequestOptions? options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; @@ -289,7 +289,7 @@ internal PipelineMessage CreateRetrieveFineTuningJobRequest(string fineTuningJob return message; } - internal PipelineMessage CreateCancelFineTuningJobRequest(string fineTuningJobId, RequestOptions? options) + internal virtual PipelineMessage CreateCancelFineTuningJobRequest(string fineTuningJobId, RequestOptions? options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; @@ -306,7 +306,7 @@ internal PipelineMessage CreateCancelFineTuningJobRequest(string fineTuningJobId return message; } - internal PipelineMessage CreateGetFineTuningJobCheckpointsRequest(string fineTuningJobId, string after, int? limit, RequestOptions? options) + internal virtual PipelineMessage CreateGetFineTuningJobCheckpointsRequest(string fineTuningJobId, string after, int? limit, RequestOptions? options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; @@ -331,7 +331,7 @@ internal PipelineMessage CreateGetFineTuningJobCheckpointsRequest(string fineTun return message; } - internal PipelineMessage CreateGetFineTuningEventsRequest(string fineTuningJobId, string after, int? limit, RequestOptions? options) + internal virtual PipelineMessage CreateGetFineTuningEventsRequest(string fineTuningJobId, string after, int? limit, RequestOptions? options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; diff --git a/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs b/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs index b54bb39b6..ae6cb0e6b 100644 --- a/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs +++ b/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs @@ -140,17 +140,17 @@ public virtual ClientResult GetJobs(string after, int? limit, RequestOptions opt /// /// [Learn more about fine-tuning](/docs/guides/fine-tuning) /// - /// The ID of the fine-tuning job. + /// The ID of the fine-tuning job. /// The request options, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task GetJobAsync(string jobId, RequestOptions options) + internal virtual async Task GetJobAsync(string fineTuningJobId, RequestOptions options) { - Argument.AssertNotNullOrEmpty(jobId, nameof(jobId)); + Argument.AssertNotNullOrEmpty(fineTuningJobId, nameof(fineTuningJobId)); - using PipelineMessage message = CreateRetrieveFineTuningJobRequest(jobId, options); + using PipelineMessage message = CreateRetrieveFineTuningJobRequest(fineTuningJobId, options); return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } @@ -162,17 +162,17 @@ internal virtual async Task GetJobAsync(string jobId, RequestOptio /// /// [Learn more about fine-tuning](/docs/guides/fine-tuning) /// - /// The ID of the fine-tuning job. + /// The ID of the fine-tuning job. /// The request options, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual ClientResult GetJob(string jobId, RequestOptions options) + internal virtual ClientResult GetJob(string fineTuningJobId, RequestOptions options) { - Argument.AssertNotNullOrEmpty(jobId, nameof(jobId)); + Argument.AssertNotNullOrEmpty(fineTuningJobId, nameof(fineTuningJobId)); - using PipelineMessage message = CreateRetrieveFineTuningJobRequest(jobId, options); + using PipelineMessage message = CreateRetrieveFineTuningJobRequest(fineTuningJobId, options); return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); } } diff --git a/.dotnet/src/Generated/BatchClient.cs b/.dotnet/src/Generated/BatchClient.cs index 3ccd2f901..b4047adb1 100644 --- a/.dotnet/src/Generated/BatchClient.cs +++ b/.dotnet/src/Generated/BatchClient.cs @@ -25,7 +25,12 @@ protected BatchClient() { } - internal PipelineMessage CreateCreateBatchRequest(BinaryContent content, RequestOptions options) + internal virtual CreateBatchOperation CreateBatchOperation(string batchId, string status, PipelineResponse response) + { + return new CreateBatchOperation(_pipeline, _endpoint, batchId, status, response); + } + + internal virtual PipelineMessage CreateCreateBatchRequest(BinaryContent content, RequestOptions options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; @@ -42,7 +47,7 @@ internal PipelineMessage CreateCreateBatchRequest(BinaryContent content, Request return message; } - internal PipelineMessage CreateGetBatchesRequest(string after, int? limit, RequestOptions options) + internal virtual PipelineMessage CreateGetBatchesRequest(string after, int? limit, RequestOptions options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; @@ -65,7 +70,7 @@ internal PipelineMessage CreateGetBatchesRequest(string after, int? limit, Reque return message; } - internal PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions options) + internal virtual PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; @@ -81,7 +86,7 @@ internal PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptio return message; } - internal PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions options) + internal virtual PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; diff --git a/.dotnet/src/Generated/FineTuningClient.cs b/.dotnet/src/Generated/FineTuningClient.cs index 7424e0331..555ffad20 100644 --- a/.dotnet/src/Generated/FineTuningClient.cs +++ b/.dotnet/src/Generated/FineTuningClient.cs @@ -31,7 +31,12 @@ internal FineTuningClient(ClientPipeline pipeline, ApiKeyCredential keyCredentia _endpoint = endpoint; } - internal PipelineMessage CreateCreateFineTuningJobRequest(BinaryContent content, RequestOptions options) + internal virtual CreateJobOperation CreateJobOperation(string jobId, string status, PipelineResponse response) + { + return new CreateJobOperation(_pipeline, _endpoint, jobId, status, response); + } + + internal virtual PipelineMessage CreateCreateFineTuningJobRequest(BinaryContent content, RequestOptions options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; @@ -48,7 +53,7 @@ internal PipelineMessage CreateCreateFineTuningJobRequest(BinaryContent content, return message; } - internal PipelineMessage CreateGetPaginatedFineTuningJobsRequest(string after, int? limit, RequestOptions options) + internal virtual PipelineMessage CreateGetPaginatedFineTuningJobsRequest(string after, int? limit, RequestOptions options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; @@ -71,40 +76,7 @@ internal PipelineMessage CreateGetPaginatedFineTuningJobsRequest(string after, i return message; } - internal PipelineMessage CreateRetrieveFineTuningJobRequest(string fineTuningJobId, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/fine_tuning/jobs/", false); - uri.AppendPath(fineTuningJobId, true); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - - internal PipelineMessage CreateCancelFineTuningJobRequest(string fineTuningJobId, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "POST"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/fine_tuning/jobs/", false); - uri.AppendPath(fineTuningJobId, true); - uri.AppendPath("/cancel", false); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - - internal PipelineMessage CreateGetFineTuningJobCheckpointsRequest(string fineTuningJobId, string after, int? limit, RequestOptions options) + internal virtual PipelineMessage CreateRetrieveFineTuningJobRequest(string fineTuningJobId, RequestOptions options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; @@ -114,40 +86,6 @@ internal PipelineMessage CreateGetFineTuningJobCheckpointsRequest(string fineTun uri.Reset(_endpoint); uri.AppendPath("/fine_tuning/jobs/", false); uri.AppendPath(fineTuningJobId, true); - uri.AppendPath("/checkpoints", false); - if (after != null) - { - uri.AppendQuery("after", after, true); - } - if (limit != null) - { - uri.AppendQuery("limit", limit.Value, true); - } - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - - internal PipelineMessage CreateGetFineTuningEventsRequest(string fineTuningJobId, string after, int? limit, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/fine_tuning/jobs/", false); - uri.AppendPath(fineTuningJobId, true); - uri.AppendPath("/events", false); - if (after != null) - { - uri.AppendQuery("after", after, true); - } - if (limit != null) - { - uri.AppendQuery("limit", limit.Value, true); - } request.Uri = uri.ToUri(); request.Headers.Set("Accept", "application/json"); message.Apply(options); From 7d10751086b75b611c9bba53828deb1463652dbd Mon Sep 17 00:00:00 2001 From: Chris Schraer Date: Mon, 9 Sep 2024 14:03:23 -0700 Subject: [PATCH 03/18] updated vector stores as best I could --- .../src/Custom/Batch/AzureBatchClient.cs | 3 +- .../AzureCreateJobOperation.Protocol.cs | 4 +- .../FineTuning/AzureFineTuningClient.cs | 4 +- ...eAddFileToVectorStoreOperation.Protocol.cs | 13 ++ .../AzureAddFileToVectorStoreOperation.cs | 23 +++ ...ureCreateBatchFileJobOperation.Protocol.cs | 28 +++ .../AzureCreateBatchFileJobOperation.cs | 31 ++++ .../AzureCreateVectorStoreOperation.cs | 25 +++ .../AzureVectorStoreClient.Protocol.cs | 166 ++++-------------- .../VectorStores/AzureVectorStoreClient.cs | 53 +++++- .../src/Custom/Batch/BatchClient.Protocol.cs | 4 +- .dotnet/src/Custom/Batch/BatchClient.cs | 78 ++++++++ .../Batch/CreateBatchOperation.Protocol.cs | 6 +- .../FineTuning/CreateJobOperation.Protocol.cs | 6 +- .../FineTuning/FineTuningClient.Protocol.cs | 4 +- .../src/Custom/FineTuning/FineTuningClient.cs | 61 +++++++ .../AddFileToVectorStoreOperation.Protocol.cs | 2 +- .../AddFileToVectorStoreOperation.cs | 4 +- .../CreateBatchFileJobOperation.Protocol.cs | 2 +- .../CreateBatchFileJobOperation.cs | 4 +- .../CreateVectorStoreOperation.Protocol.cs | 5 +- .../CreateVectorStoreOperation.cs | 4 +- .../VectorStoreClient.Convenience.cs | 16 -- .../VectorStoreClient.Protocol.cs | 4 +- .../Custom/VectorStores/VectorStoreClient.cs | 89 +++++++++- 25 files changed, 459 insertions(+), 180 deletions(-) create mode 100644 .dotnet.azure/src/Custom/VectorStores/AzureAddFileToVectorStoreOperation.Protocol.cs create mode 100644 .dotnet.azure/src/Custom/VectorStores/AzureAddFileToVectorStoreOperation.cs create mode 100644 .dotnet.azure/src/Custom/VectorStores/AzureCreateBatchFileJobOperation.Protocol.cs create mode 100644 .dotnet.azure/src/Custom/VectorStores/AzureCreateBatchFileJobOperation.cs create mode 100644 .dotnet.azure/src/Custom/VectorStores/AzureCreateVectorStoreOperation.cs diff --git a/.dotnet.azure/src/Custom/Batch/AzureBatchClient.cs b/.dotnet.azure/src/Custom/Batch/AzureBatchClient.cs index 02a1d9502..ad7e55165 100644 --- a/.dotnet.azure/src/Custom/Batch/AzureBatchClient.cs +++ b/.dotnet.azure/src/Custom/Batch/AzureBatchClient.cs @@ -3,7 +3,6 @@ using System.ClientModel; using System.ClientModel.Primitives; -using OpenAI.Batch; namespace Azure.AI.OpenAI.Batch; @@ -36,7 +35,7 @@ internal AzureBatchClient( protected AzureBatchClient() { } - internal override CreateBatchOperation CreateBatchOperation(string batchId, string status, PipelineResponse response) + internal override CreateBatchOperation CreateCreateBatchOperation(string batchId, string status, PipelineResponse response) { return new AzureCreateBatchOperation(Pipeline, _endpoint, batchId, status, response, _deploymentName, _apiVersion); } diff --git a/.dotnet.azure/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs b/.dotnet.azure/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs index 8231b5f7a..d7c4caec0 100644 --- a/.dotnet.azure/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs +++ b/.dotnet.azure/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs @@ -4,12 +4,12 @@ #nullable enable -namespace Azure.AI.OpenAI.Custom.FineTuning; +namespace Azure.AI.OpenAI.FineTuning; /// /// A long-running operation for creating a new model from a given dataset. /// -public partial class AzureCreateJobOperation : CreateJobOperation +public class AzureCreateJobOperation : CreateJobOperation { private readonly PipelineMessageClassifier DeleteJobClassifier = PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); private readonly ClientPipeline _pipeline; diff --git a/.dotnet.azure/src/Custom/FineTuning/AzureFineTuningClient.cs b/.dotnet.azure/src/Custom/FineTuning/AzureFineTuningClient.cs index 9f4c7ff1c..2f05d1678 100644 --- a/.dotnet.azure/src/Custom/FineTuning/AzureFineTuningClient.cs +++ b/.dotnet.azure/src/Custom/FineTuning/AzureFineTuningClient.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using Azure.AI.OpenAI.Custom.FineTuning; -using OpenAI.FineTuning; using System.ClientModel; using System.ClientModel.Primitives; @@ -33,7 +31,7 @@ internal AzureFineTuningClient( protected AzureFineTuningClient() { } - internal override CreateJobOperation CreateJobOperation(string jobId, string status, PipelineResponse response) + internal override CreateJobOperation CreateCreateJobOperation(string jobId, string status, PipelineResponse response) { return new AzureCreateJobOperation(Pipeline, _endpoint, jobId, status, response, _apiVersion); } diff --git a/.dotnet.azure/src/Custom/VectorStores/AzureAddFileToVectorStoreOperation.Protocol.cs b/.dotnet.azure/src/Custom/VectorStores/AzureAddFileToVectorStoreOperation.Protocol.cs new file mode 100644 index 000000000..9412f788e --- /dev/null +++ b/.dotnet.azure/src/Custom/VectorStores/AzureAddFileToVectorStoreOperation.Protocol.cs @@ -0,0 +1,13 @@ +using System.ClientModel.Primitives; + +namespace Azure.AI.OpenAI.VectorStores; +public partial class AzureAddFileToVectorStoreOperation : AddFileToVectorStoreOperation +{ + internal override PipelineMessage CreateGetVectorStoreFileRequest(string vectorStoreId, string fileId, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(_pipeline, _endpoint, _apiVersion) + .WithMethod("GET") + .WithPath("vector_stores", vectorStoreId, "files", fileId) + .WithAccept("application/json") + .WithOptions(options) + .Build(); +} diff --git a/.dotnet.azure/src/Custom/VectorStores/AzureAddFileToVectorStoreOperation.cs b/.dotnet.azure/src/Custom/VectorStores/AzureAddFileToVectorStoreOperation.cs new file mode 100644 index 000000000..532f2ff68 --- /dev/null +++ b/.dotnet.azure/src/Custom/VectorStores/AzureAddFileToVectorStoreOperation.cs @@ -0,0 +1,23 @@ +using System.ClientModel.Primitives; +using System.ClientModel; +using System.Diagnostics.CodeAnalysis; + +namespace Azure.AI.OpenAI.VectorStores; +[Experimental("OPENAI001")] +public partial class AzureAddFileToVectorStoreOperation : AddFileToVectorStoreOperation +{ + private readonly string _apiVersion; + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + internal AzureAddFileToVectorStoreOperation( + ClientPipeline pipeline, + Uri endpoint, + ClientResult result, + string apiVersion) + : base(pipeline, endpoint, result) + { + _pipeline = pipeline; + _endpoint = endpoint; + _apiVersion = apiVersion; + } +} diff --git a/.dotnet.azure/src/Custom/VectorStores/AzureCreateBatchFileJobOperation.Protocol.cs b/.dotnet.azure/src/Custom/VectorStores/AzureCreateBatchFileJobOperation.Protocol.cs new file mode 100644 index 000000000..a9244f852 --- /dev/null +++ b/.dotnet.azure/src/Custom/VectorStores/AzureCreateBatchFileJobOperation.Protocol.cs @@ -0,0 +1,28 @@ +using System.ClientModel; +using System.ClientModel.Primitives; + +#nullable enable + +namespace Azure.AI.OpenAI.VectorStores; +public partial class AzureCreateBatchFileJobOperation +{ + public override IAsyncEnumerable GetFilesInBatchAsync(int? limit, string? order, string? after, string? before, string? filter, RequestOptions? options) + { + AzureVectorStoreFileBatchesPageEnumerator enumerator = new(_pipeline, _endpoint, _vectorStoreId, _batchId, limit, order, after, before, filter, _apiVersion, options); + return PageCollectionHelpers.CreateAsync(enumerator); + } + + public override IEnumerable GetFilesInBatch(int? limit, string? order, string? after, string? before, string? filter, RequestOptions? options) + { + AzureVectorStoreFileBatchesPageEnumerator enumerator = new(_pipeline, _endpoint, _vectorStoreId, _batchId, limit, order, after, before, filter, _apiVersion, options); + return PageCollectionHelpers.Create(enumerator); + } + + internal override PipelineMessage CreateCancelVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestOptions? options) + => new AzureOpenAIPipelineMessageBuilder(_pipeline, _endpoint, _apiVersion) + .WithMethod("POST") + .WithPath("vector_stores", vectorStoreId, "file_batches", batchId, "cancel") + .WithAccept("application/json") + .WithOptions(options) + .Build(); +} diff --git a/.dotnet.azure/src/Custom/VectorStores/AzureCreateBatchFileJobOperation.cs b/.dotnet.azure/src/Custom/VectorStores/AzureCreateBatchFileJobOperation.cs new file mode 100644 index 000000000..2f0096bb1 --- /dev/null +++ b/.dotnet.azure/src/Custom/VectorStores/AzureCreateBatchFileJobOperation.cs @@ -0,0 +1,31 @@ +using Azure.Core; +using System.ClientModel.Primitives; +using System.ClientModel; +using System.Diagnostics.CodeAnalysis; + +namespace Azure.AI.OpenAI.VectorStores; + +[Experimental("OPENAI001")] +public partial class AzureCreateBatchFileJobOperation : CreateBatchFileJobOperation +{ + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _apiVersion; + private readonly string _vectorStoreId; + private readonly string _batchId; + + internal AzureCreateBatchFileJobOperation( + ClientPipeline pipeline, + Uri endpoint, + ClientResult result, + string apiVersion) + : base(pipeline, endpoint, result) + { + _pipeline = pipeline; + _endpoint = endpoint; + _apiVersion = apiVersion; + + _vectorStoreId = Value.VectorStoreId; + _batchId = Value.BatchId; + } +} diff --git a/.dotnet.azure/src/Custom/VectorStores/AzureCreateVectorStoreOperation.cs b/.dotnet.azure/src/Custom/VectorStores/AzureCreateVectorStoreOperation.cs new file mode 100644 index 000000000..a0707f371 --- /dev/null +++ b/.dotnet.azure/src/Custom/VectorStores/AzureCreateVectorStoreOperation.cs @@ -0,0 +1,25 @@ +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Diagnostics.CodeAnalysis; + +namespace Azure.AI.OpenAI.VectorStores; + +[Experimental("OPENAI001")] +public class AzureCreateVectorStoreOperation : CreateVectorStoreOperation +{ + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _apiVersion; + + internal AzureCreateVectorStoreOperation( + ClientPipeline pipeline, + Uri endpoint, + ClientResult result, + string apiVersion) + : base(pipeline, endpoint, result) + { + _pipeline = pipeline; + _endpoint = endpoint; + _apiVersion = apiVersion; + } +} diff --git a/.dotnet.azure/src/Custom/VectorStores/AzureVectorStoreClient.Protocol.cs b/.dotnet.azure/src/Custom/VectorStores/AzureVectorStoreClient.Protocol.cs index b14c3b56e..ef68c999d 100644 --- a/.dotnet.azure/src/Custom/VectorStores/AzureVectorStoreClient.Protocol.cs +++ b/.dotnet.azure/src/Custom/VectorStores/AzureVectorStoreClient.Protocol.cs @@ -21,19 +21,7 @@ public override IEnumerable GetVectorStores(int? limit, string ord return PageCollectionHelpers.Create(enumerator); } - public override async Task CreateVectorStoreAsync(BinaryContent content, RequestOptions options = null) - { - using PipelineMessage message = CreateCreateVectorStoreRequest(content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - - public override ClientResult CreateVectorStore(BinaryContent content, RequestOptions options = null) - { - using PipelineMessage message = CreateCreateVectorStoreRequest(content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - - public override async Task GetVectorStoreAsync(string vectorStoreId, RequestOptions options) + internal override async Task GetVectorStoreAsync(string vectorStoreId, RequestOptions options) { Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); @@ -41,7 +29,7 @@ public override async Task GetVectorStoreAsync(string vectorStoreI return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } - public override ClientResult GetVectorStore(string vectorStoreId, RequestOptions options) + internal override ClientResult GetVectorStore(string vectorStoreId, RequestOptions options) { Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); @@ -99,40 +87,30 @@ public override IEnumerable GetFileAssociations(string vectorStore return PageCollectionHelpers.Create(enumerator); } - public override async Task AddFileToVectorStoreAsync(string vectorStoreId, BinaryContent content, RequestOptions options = null) + public override async Task AddFileToVectorStoreAsync(string vectorStoreId, BinaryContent content, bool waitUntilCompleted, RequestOptions options = null) { Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); Argument.AssertNotNull(content, nameof(content)); using PipelineMessage message = CreateCreateVectorStoreFileRequest(vectorStoreId, content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + PipelineResponse response = await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); + VectorStoreFileAssociation value = VectorStoreFileAssociation.FromResponse(response); + + AzureAddFileToVectorStoreOperation operation = new(Pipeline, _endpoint, ClientResult.FromValue(value, response), _apiVersion); + return await operation.WaitUntilAsync(waitUntilCompleted, options).ConfigureAwait(false); } - public override ClientResult AddFileToVectorStore(string vectorStoreId, BinaryContent content, RequestOptions options = null) + public override AddFileToVectorStoreOperation AddFileToVectorStore(string vectorStoreId, BinaryContent content, bool waitUntilCompleted, RequestOptions options = null) { Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); Argument.AssertNotNull(content, nameof(content)); using PipelineMessage message = CreateCreateVectorStoreFileRequest(vectorStoreId, content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } + PipelineResponse response = Pipeline.ProcessMessage(message, options); + VectorStoreFileAssociation value = VectorStoreFileAssociation.FromResponse(response); - public override async Task GetFileAssociationAsync(string vectorStoreId, string fileId, RequestOptions options) - { - Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - - using PipelineMessage message = CreateGetVectorStoreFileRequest(vectorStoreId, fileId, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - - public override ClientResult GetFileAssociation(string vectorStoreId, string fileId, RequestOptions options) - { - Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - - using PipelineMessage message = CreateGetVectorStoreFileRequest(vectorStoreId, fileId, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); + AzureAddFileToVectorStoreOperation operation = new(Pipeline, _endpoint, ClientResult.FromValue(value, response), _apiVersion); + return operation.WaitUntil(waitUntilCompleted, options); } public override async Task RemoveFileFromStoreAsync(string vectorStoreId, string fileId, RequestOptions options) @@ -153,87 +131,40 @@ public override ClientResult RemoveFileFromStore(string vectorStoreId, string fi return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } - public override async Task CreateBatchFileJobAsync(string vectorStoreId, BinaryContent content, RequestOptions options = null) + public override async Task CreateBatchFileJobAsync( + string vectorStoreId, + BinaryContent content, + bool waitUntilCompleted, + RequestOptions options = null) { Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); Argument.AssertNotNull(content, nameof(content)); using PipelineMessage message = CreateCreateVectorStoreFileBatchRequest(vectorStoreId, content, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + PipelineResponse response = await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); + VectorStoreBatchFileJob job = VectorStoreBatchFileJob.FromResponse(response); + + AzureCreateBatchFileJobOperation operation = new(Pipeline, _endpoint, ClientResult.FromValue(job, response), _apiVersion); + return await operation.WaitUntilAsync(waitUntilCompleted, options).ConfigureAwait(false); } - public override ClientResult CreateBatchFileJob(string vectorStoreId, BinaryContent content, RequestOptions options = null) + public override CreateBatchFileJobOperation CreateBatchFileJob( + string vectorStoreId, + BinaryContent content, + bool waitUntilCompleted, + RequestOptions options = null) { Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); Argument.AssertNotNull(content, nameof(content)); using PipelineMessage message = CreateCreateVectorStoreFileBatchRequest(vectorStoreId, content, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - - public override async Task GetBatchFileJobAsync(string vectorStoreId, string batchId, RequestOptions options) - { - Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); - - using PipelineMessage message = CreateGetVectorStoreFileBatchRequest(vectorStoreId, batchId, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); - } - - public override ClientResult GetBatchFileJob(string vectorStoreId, string batchId, RequestOptions options) - { - Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); - - using PipelineMessage message = CreateGetVectorStoreFileBatchRequest(vectorStoreId, batchId, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - - public override async Task CancelBatchFileJobAsync(string vectorStoreId, string batchId, RequestOptions options) - { - Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); + PipelineResponse response = Pipeline.ProcessMessage(message, options); + VectorStoreBatchFileJob job = VectorStoreBatchFileJob.FromResponse(response); - using PipelineMessage message = CreateCancelVectorStoreFileBatchRequest(vectorStoreId, batchId, options); - return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + AzureCreateBatchFileJobOperation operation = new(Pipeline, _endpoint, ClientResult.FromValue(job, response), _apiVersion); + return operation.WaitUntil(waitUntilCompleted, options); } - public override ClientResult CancelBatchFileJob(string vectorStoreId, string batchId, RequestOptions options) - { - Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); - - using PipelineMessage message = CreateCancelVectorStoreFileBatchRequest(vectorStoreId, batchId, options); - return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); - } - - public override IAsyncEnumerable GetFileAssociationsAsync(string vectorStoreId, string batchId, int? limit, string order, string after, string before, string filter, RequestOptions options) - { - Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); - - AzureVectorStoreFileBatchesPageEnumerator enumerator = new(Pipeline, _endpoint, vectorStoreId, batchId, limit, order, after, before, filter, _apiVersion, options); - return PageCollectionHelpers.CreateAsync(enumerator); - } - - public override IEnumerable GetFileAssociations(string vectorStoreId, string batchId, int? limit, string order, string after, string before, string filter, RequestOptions options) - { - Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); - - AzureVectorStoreFileBatchesPageEnumerator enumerator = new(Pipeline, _endpoint, vectorStoreId, batchId, limit, order, after, before, filter, _apiVersion, options); - return PageCollectionHelpers.Create(enumerator); - } - - private new PipelineMessage CreateCreateVectorStoreRequest(BinaryContent content, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("POST") - .WithPath("vector_stores") - .WithContent(content, "application/json") - .WithAccept("application/json") - .WithOptions(options) - .Build(); - private new PipelineMessage CreateGetVectorStoreRequest(string vectorStoreId, RequestOptions options) => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) .WithMethod("GET") @@ -268,14 +199,6 @@ public override IEnumerable GetFileAssociations(string vectorStore .WithOptions(options) .Build(); - private new PipelineMessage CreateGetVectorStoreFileRequest(string vectorStoreId, string fileId, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("GET") - .WithPath("vector_stores", vectorStoreId, "files", fileId) - .WithAccept("application/json") - .WithOptions(options) - .Build(); - private new PipelineMessage CreateDeleteVectorStoreFileRequest(string vectorStoreId, string fileId, RequestOptions options) => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) .WithMethod("DELETE") @@ -283,29 +206,4 @@ public override IEnumerable GetFileAssociations(string vectorStore .WithAccept("application/json") .WithOptions(options) .Build(); - - private new PipelineMessage CreateCreateVectorStoreFileBatchRequest(string vectorStoreId, BinaryContent content, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("POST") - .WithPath("vector_stores", vectorStoreId, "file_batches") - .WithContent(content, "application/json") - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - private new PipelineMessage CreateGetVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("GET") - .WithPath("vector_stores", vectorStoreId, "file_batches", batchId) - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - private new PipelineMessage CreateCancelVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("POST") - .WithPath("vector_stores", vectorStoreId, "file_batches", batchId, "cancel") - .WithAccept("application/json") - .WithOptions(options) - .Build(); } diff --git a/.dotnet.azure/src/Custom/VectorStores/AzureVectorStoreClient.cs b/.dotnet.azure/src/Custom/VectorStores/AzureVectorStoreClient.cs index 5d6bcd29a..4b8141363 100644 --- a/.dotnet.azure/src/Custom/VectorStores/AzureVectorStoreClient.cs +++ b/.dotnet.azure/src/Custom/VectorStores/AzureVectorStoreClient.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using OpenAI.VectorStores; +using System.ClientModel; using System.ClientModel.Primitives; using System.Diagnostics.CodeAnalysis; @@ -32,4 +32,55 @@ internal AzureVectorStoreClient( protected AzureVectorStoreClient() { } + + internal override CreateVectorStoreOperation CreateCreateVectorStoreOperation(ClientResult result) + { + return new AzureCreateVectorStoreOperation(Pipeline, _endpoint, result, _apiVersion); + } + + internal override AddFileToVectorStoreOperation CreateAddFileToVectorStoreOperation(ClientResult result) + { + return new AzureAddFileToVectorStoreOperation(Pipeline, _endpoint, result, _apiVersion); + } + + internal override CreateBatchFileJobOperation CreateBatchFileJobOperation(ClientResult result) + { + return new AzureCreateBatchFileJobOperation(Pipeline, _endpoint, result, _apiVersion); + } + + internal override PipelineMessage CreateGetVectorStoreFileRequest(string vectorStoreId, string fileId, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) + .WithMethod("GET") + .WithPath("vector_stores", vectorStoreId, "files", fileId) + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateCreateVectorStoreRequest(BinaryContent content, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) + .WithMethod("POST") + .WithPath("vector_stores") + .WithContent(content, "application/json") + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateCreateVectorStoreFileBatchRequest(string vectorStoreId, BinaryContent content, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) + .WithMethod("POST") + .WithPath("vector_stores", vectorStoreId, "file_batches") + .WithContent(content, "application/json") + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateGetVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) + .WithMethod("GET") + .WithPath("vector_stores", vectorStoreId, "file_batches", batchId) + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + } diff --git a/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs b/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs index 9f72dfd7b..4f94cb8db 100644 --- a/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs +++ b/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs @@ -19,7 +19,7 @@ public partial class BatchClient /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// Service returned a non-success status code. - /// A that can be used to wait for + /// A that can be used to wait for /// the operation to complete, or cancel the operation. public virtual async Task CreateBatchAsync(BinaryContent content, bool waitUntilCompleted, RequestOptions options = null) { @@ -48,7 +48,7 @@ public virtual async Task CreateBatchAsync(BinaryContent c /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// Service returned a non-success status code. - /// A that can be used to wait for + /// A that can be used to wait for /// the operation to complete, or cancel the operation. public virtual CreateBatchOperation CreateBatch(BinaryContent content, bool waitUntilCompleted, RequestOptions options = null) { diff --git a/.dotnet/src/Custom/Batch/BatchClient.cs b/.dotnet/src/Custom/Batch/BatchClient.cs index 484444dee..04c4d9f5a 100644 --- a/.dotnet/src/Custom/Batch/BatchClient.cs +++ b/.dotnet/src/Custom/Batch/BatchClient.cs @@ -64,5 +64,83 @@ protected internal BatchClient(ClientPipeline pipeline, Uri endpoint, OpenAIClie { _pipeline = pipeline; _endpoint = endpoint; + } + + internal virtual CreateBatchOperation CreateCreateBatchOperation(string batchId, string status, PipelineResponse response) + { + return new CreateBatchOperation(_pipeline, _endpoint, batchId, status, response); + } + + internal virtual PipelineMessage CreateCreateBatchRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/batches", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateGetBatchesRequest(string after, int? limit, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/batches", false); + if (after != null) + { + uri.AppendQuery("after", after, true); + } + if (limit != null) + { + uri.AppendQuery("limit", limit.Value, true); + } + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/batches/", false); + uri.AppendPath(batchId, true); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/batches/", false); + uri.AppendPath(batchId, true); + uri.AppendPath("/cancel", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; } } diff --git a/.dotnet/src/Custom/Batch/CreateBatchOperation.Protocol.cs b/.dotnet/src/Custom/Batch/CreateBatchOperation.Protocol.cs index b626f1a08..addb91fc6 100644 --- a/.dotnet/src/Custom/Batch/CreateBatchOperation.Protocol.cs +++ b/.dotnet/src/Custom/Batch/CreateBatchOperation.Protocol.cs @@ -13,7 +13,7 @@ namespace OpenAI.Batch; /// A long-running operation for executing a batch from an uploaded file of /// requests. /// -public partial class CreateBatchOperation : OperationResult +public class CreateBatchOperation : OperationResult { private readonly ClientPipeline _pipeline; private readonly Uri _endpoint; @@ -65,7 +65,7 @@ public static async Task RehydrateAsync(BatchClient client using JsonDocument doc = JsonDocument.Parse(response.Content); string status = doc.RootElement.GetProperty("status"u8).GetString()!; - return client.CreateBatchOperation(token.BatchId, status, response); + return client.CreateCreateBatchOperation(token.BatchId, status, response); } /// @@ -92,7 +92,7 @@ public static CreateBatchOperation Rehydrate(BatchClient client, ContinuationTok using JsonDocument doc = JsonDocument.Parse(response.Content); string status = doc.RootElement.GetProperty("status"u8).GetString()!; - return client.CreateBatchOperation(token.BatchId, status, response); + return client.CreateCreateBatchOperation(token.BatchId, status, response); } /// diff --git a/.dotnet/src/Custom/FineTuning/CreateJobOperation.Protocol.cs b/.dotnet/src/Custom/FineTuning/CreateJobOperation.Protocol.cs index 6ecb5cb9e..3922f7f94 100644 --- a/.dotnet/src/Custom/FineTuning/CreateJobOperation.Protocol.cs +++ b/.dotnet/src/Custom/FineTuning/CreateJobOperation.Protocol.cs @@ -12,7 +12,7 @@ namespace OpenAI.FineTuning; /// /// A long-running operation for creating a new model from a given dataset. /// -public partial class CreateJobOperation : OperationResult +public class CreateJobOperation : OperationResult { private readonly ClientPipeline _pipeline; private readonly Uri _endpoint; @@ -63,7 +63,7 @@ public static async Task RehydrateAsync(FineTuningClient cli using JsonDocument doc = JsonDocument.Parse(response.Content); string status = doc.RootElement.GetProperty("status"u8).GetString()!; - return new CreateJobOperation(client.Pipeline, client.Endpoint, token.JobId, status, response); + return client.CreateCreateJobOperation(token.JobId, status, response); } /// @@ -90,7 +90,7 @@ public static CreateJobOperation Rehydrate(FineTuningClient client, Continuation using JsonDocument doc = JsonDocument.Parse(response.Content); string status = doc.RootElement.GetProperty("status"u8).GetString()!; - return client.CreateJobOperation(token.JobId, status, response); + return client.CreateCreateJobOperation(token.JobId, status, response); } /// diff --git a/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs b/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs index ae6cb0e6b..917344f8a 100644 --- a/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs +++ b/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs @@ -38,7 +38,7 @@ public partial class FineTuningClient /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// Service returned a non-success status code. - /// A that can be used to wait for + /// A that can be used to wait for /// the operation to complete, get information about the fine tuning job, or /// cancel the operation. public virtual async Task CreateJobAsync( @@ -77,7 +77,7 @@ public virtual async Task CreateJobAsync( /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// Service returned a non-success status code. - /// A that can be used to wait for + /// A that can be used to wait for /// the operation to complete, get information about the fine tuning job, or /// cancel the operation. public virtual CreateJobOperation CreateJob( diff --git a/.dotnet/src/Custom/FineTuning/FineTuningClient.cs b/.dotnet/src/Custom/FineTuning/FineTuningClient.cs index 53ac0b085..6526b062c 100644 --- a/.dotnet/src/Custom/FineTuning/FineTuningClient.cs +++ b/.dotnet/src/Custom/FineTuning/FineTuningClient.cs @@ -63,5 +63,66 @@ protected internal FineTuningClient(ClientPipeline pipeline, Uri endpoint, OpenA { _pipeline = pipeline; _endpoint = endpoint; + } + + internal virtual CreateJobOperation CreateCreateJobOperation(string jobId, string status, PipelineResponse response) + { + return new CreateJobOperation(_pipeline, _endpoint, jobId, status, response); + } + + internal virtual PipelineMessage CreateCreateFineTuningJobRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/fine_tuning/jobs", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateGetPaginatedFineTuningJobsRequest(string after, int? limit, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/fine_tuning/jobs", false); + if (after != null) + { + uri.AppendQuery("after", after, true); + } + if (limit != null) + { + uri.AppendQuery("limit", limit.Value, true); + } + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateRetrieveFineTuningJobRequest(string fineTuningJobId, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/fine_tuning/jobs/", false); + uri.AppendPath(fineTuningJobId, true); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; } } diff --git a/.dotnet/src/Custom/VectorStores/AddFileToVectorStoreOperation.Protocol.cs b/.dotnet/src/Custom/VectorStores/AddFileToVectorStoreOperation.Protocol.cs index def381069..254232f1a 100644 --- a/.dotnet/src/Custom/VectorStores/AddFileToVectorStoreOperation.Protocol.cs +++ b/.dotnet/src/Custom/VectorStores/AddFileToVectorStoreOperation.Protocol.cs @@ -45,7 +45,7 @@ public virtual ClientResult GetFileAssociation(RequestOptions? options) return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); } - internal PipelineMessage CreateGetVectorStoreFileRequest(string vectorStoreId, string fileId, RequestOptions? options) + internal virtual PipelineMessage CreateGetVectorStoreFileRequest(string vectorStoreId, string fileId, RequestOptions? options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; diff --git a/.dotnet/src/Custom/VectorStores/AddFileToVectorStoreOperation.cs b/.dotnet/src/Custom/VectorStores/AddFileToVectorStoreOperation.cs index e891d8d39..5d8cf60ac 100644 --- a/.dotnet/src/Custom/VectorStores/AddFileToVectorStoreOperation.cs +++ b/.dotnet/src/Custom/VectorStores/AddFileToVectorStoreOperation.cs @@ -73,7 +73,7 @@ public static async Task RehydrateAsync(VectorSto PipelineResponse response = result.GetRawResponse(); VectorStoreFileAssociation value = VectorStoreFileAssociation.FromResponse(response); - return new AddFileToVectorStoreOperation(client.Pipeline, client.Endpoint, FromValue(value, response)); + return client.CreateAddFileToVectorStoreOperation(FromValue(value, response)); } /// @@ -98,7 +98,7 @@ public static AddFileToVectorStoreOperation Rehydrate(VectorStoreClient client, PipelineResponse response = result.GetRawResponse(); VectorStoreFileAssociation value = VectorStoreFileAssociation.FromResponse(response); - return new AddFileToVectorStoreOperation(client.Pipeline, client.Endpoint, FromValue(value, response)); + return client.CreateAddFileToVectorStoreOperation(FromValue(value, response)); } /// diff --git a/.dotnet/src/Custom/VectorStores/CreateBatchFileJobOperation.Protocol.cs b/.dotnet/src/Custom/VectorStores/CreateBatchFileJobOperation.Protocol.cs index e04a58f78..5fbe52f11 100644 --- a/.dotnet/src/Custom/VectorStores/CreateBatchFileJobOperation.Protocol.cs +++ b/.dotnet/src/Custom/VectorStores/CreateBatchFileJobOperation.Protocol.cs @@ -159,7 +159,7 @@ internal PipelineMessage CreateGetVectorStoreFileBatchRequest(string vectorStore return message; } - internal PipelineMessage CreateCancelVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestOptions? options) + internal virtual PipelineMessage CreateCancelVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestOptions? options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; diff --git a/.dotnet/src/Custom/VectorStores/CreateBatchFileJobOperation.cs b/.dotnet/src/Custom/VectorStores/CreateBatchFileJobOperation.cs index 6cb22eb4d..995a05a45 100644 --- a/.dotnet/src/Custom/VectorStores/CreateBatchFileJobOperation.cs +++ b/.dotnet/src/Custom/VectorStores/CreateBatchFileJobOperation.cs @@ -76,7 +76,7 @@ public static async Task RehydrateAsync(VectorStore PipelineResponse response = result.GetRawResponse(); VectorStoreBatchFileJob job = VectorStoreBatchFileJob.FromResponse(response); - return new CreateBatchFileJobOperation(client.Pipeline, client.Endpoint, FromValue(job, response)); + return client.CreateBatchFileJobOperation(FromValue(job, response)); } /// @@ -101,7 +101,7 @@ public static CreateBatchFileJobOperation Rehydrate(VectorStoreClient client, Co PipelineResponse response = result.GetRawResponse(); VectorStoreBatchFileJob job = VectorStoreBatchFileJob.FromResponse(response); - return new CreateBatchFileJobOperation(client.Pipeline, client.Endpoint, FromValue(job, response)); + return client.CreateBatchFileJobOperation(FromValue(job, response)); } /// diff --git a/.dotnet/src/Custom/VectorStores/CreateVectorStoreOperation.Protocol.cs b/.dotnet/src/Custom/VectorStores/CreateVectorStoreOperation.Protocol.cs index 0068dfc3d..44fe10a05 100644 --- a/.dotnet/src/Custom/VectorStores/CreateVectorStoreOperation.Protocol.cs +++ b/.dotnet/src/Custom/VectorStores/CreateVectorStoreOperation.Protocol.cs @@ -1,7 +1,10 @@ -using System; +using OpenAI.Batch; +using System; using System.ClientModel; using System.ClientModel.Primitives; using System.ComponentModel; +using System.Text.Json; +using System.Threading; using System.Threading.Tasks; #nullable enable diff --git a/.dotnet/src/Custom/VectorStores/CreateVectorStoreOperation.cs b/.dotnet/src/Custom/VectorStores/CreateVectorStoreOperation.cs index 16e1d334f..bfb439f61 100644 --- a/.dotnet/src/Custom/VectorStores/CreateVectorStoreOperation.cs +++ b/.dotnet/src/Custom/VectorStores/CreateVectorStoreOperation.cs @@ -68,7 +68,7 @@ public static async Task RehydrateAsync(VectorStoreC PipelineResponse response = result.GetRawResponse(); VectorStore vectorStore = VectorStore.FromResponse(response); - return new CreateVectorStoreOperation(client.Pipeline, client.Endpoint, FromValue(vectorStore, response)); + return client.CreateCreateVectorStoreOperation(FromValue(vectorStore, response)); } /// @@ -93,7 +93,7 @@ public static CreateVectorStoreOperation Rehydrate(VectorStoreClient client, Con PipelineResponse response = result.GetRawResponse(); VectorStore vectorStore = VectorStore.FromResponse(response); - return new CreateVectorStoreOperation(client.Pipeline, client.Endpoint, FromValue(vectorStore, response)); + return client.CreateCreateVectorStoreOperation(FromValue(vectorStore, response)); } /// diff --git a/.dotnet/src/Custom/VectorStores/VectorStoreClient.Convenience.cs b/.dotnet/src/Custom/VectorStores/VectorStoreClient.Convenience.cs index 62acf78af..8a0e129a7 100644 --- a/.dotnet/src/Custom/VectorStores/VectorStoreClient.Convenience.cs +++ b/.dotnet/src/Custom/VectorStores/VectorStoreClient.Convenience.cs @@ -26,22 +26,6 @@ public virtual Task> ModifyVectorStoreAsync(VectorStor public virtual ClientResult ModifyVectorStore(VectorStore vectorStore, VectorStoreModificationOptions options) => ModifyVectorStore(vectorStore?.Id, options); - /// - /// Gets an up-to-date instance of an existing vector store. - /// - /// The existing vector store instance to get an updated instance of. - /// The refreshed vector store instance. - public virtual Task> GetVectorStoreAsync(VectorStore vectorStore) - => GetVectorStoreAsync(vectorStore?.Id); - - /// - /// Gets an up-to-date instance of an existing vector store. - /// - /// The existing vector store instance to get an updated instance of. - /// The refreshed vector store instance. - public virtual ClientResult GetVectorStore(VectorStore vectorStore) - => GetVectorStore(vectorStore?.Id); - /// /// Deletes a vector store. /// diff --git a/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs b/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs index 78ae9dea5..10c0d13e3 100644 --- a/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs +++ b/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs @@ -145,7 +145,7 @@ public virtual CreateVectorStoreOperation CreateVectorStore(BinaryContent conten /// Service returned a non-success status code. /// The response returned from the service. [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task GetVectorStoreAsync(string vectorStoreId, RequestOptions options) + internal virtual async Task GetVectorStoreAsync(string vectorStoreId, RequestOptions options) { Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); @@ -163,7 +163,7 @@ public virtual async Task GetVectorStoreAsync(string vectorStoreId /// Service returned a non-success status code. /// The response returned from the service. [EditorBrowsable(EditorBrowsableState.Never)] - public virtual ClientResult GetVectorStore(string vectorStoreId, RequestOptions options) + internal virtual ClientResult GetVectorStore(string vectorStoreId, RequestOptions options) { Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); diff --git a/.dotnet/src/Custom/VectorStores/VectorStoreClient.cs b/.dotnet/src/Custom/VectorStores/VectorStoreClient.cs index 69e6e0c32..9d630e9ab 100644 --- a/.dotnet/src/Custom/VectorStores/VectorStoreClient.cs +++ b/.dotnet/src/Custom/VectorStores/VectorStoreClient.cs @@ -81,6 +81,21 @@ protected internal VectorStoreClient(ClientPipeline pipeline, Uri endpoint, Open { _pipeline = pipeline; _endpoint = endpoint; + } + + internal virtual CreateVectorStoreOperation CreateCreateVectorStoreOperation(ClientResult result) + { + return new CreateVectorStoreOperation(_pipeline, _endpoint, result); + } + + internal virtual AddFileToVectorStoreOperation CreateAddFileToVectorStoreOperation(ClientResult result) + { + return new AddFileToVectorStoreOperation(Pipeline, _endpoint, result); + } + + internal virtual CreateBatchFileJobOperation CreateBatchFileJobOperation(ClientResult result) + { + return new CreateBatchFileJobOperation(Pipeline, _endpoint, result); } /// Creates a vector store. @@ -121,7 +136,7 @@ public virtual CreateVectorStoreOperation CreateVectorStore(bool waitUntilComple /// The ID of the vector store to retrieve. /// A token that can be used to cancel this method call. /// A representation of an existing . - public virtual async Task> GetVectorStoreAsync(string vectorStoreId, CancellationToken cancellationToken = default) + internal virtual async Task> GetVectorStoreAsync(string vectorStoreId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); @@ -551,5 +566,77 @@ public virtual CreateBatchFileJobOperation CreateBatchFileJob( RequestOptions options = cancellationToken.ToRequestOptions(); return CreateBatchFileJob(vectorStoreId, content, waitUntilCompleted, options); + } + + internal virtual PipelineMessage CreateCreateVectorStoreFileBatchRequest(string vectorStoreId, BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + uri.AppendPath("/file_batches", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateGetVectorStoreFileRequest(string vectorStoreId, string fileId, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + uri.AppendPath("/files/", false); + uri.AppendPath(fileId, true); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateCreateVectorStoreRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateGetVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + uri.AppendPath("/file_batches/", false); + uri.AppendPath(batchId, true); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; } } From 5e29c7723d90671a031c094e742cb808d56dd309 Mon Sep 17 00:00:00 2001 From: Chris Schraer Date: Tue, 10 Sep 2024 10:16:25 -0700 Subject: [PATCH 04/18] regenerate tsp --- .dotnet/src/Generated/BatchClient.cs | 138 ++++---------- .dotnet/src/Generated/FineTuningClient.cs | 200 +++++++++++---------- .dotnet/src/Generated/VectorStoreClient.cs | 72 -------- 3 files changed, 133 insertions(+), 277 deletions(-) diff --git a/.dotnet/src/Generated/BatchClient.cs b/.dotnet/src/Generated/BatchClient.cs index b4047adb1..50ba7fce7 100644 --- a/.dotnet/src/Generated/BatchClient.cs +++ b/.dotnet/src/Generated/BatchClient.cs @@ -1,109 +1,31 @@ -// - -#nullable disable - -using System; -using System.ClientModel; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace OpenAI.Batch -{ - // Data plane generated sub-client. - public partial class BatchClient - { - private const string AuthorizationHeader = "Authorization"; - private readonly ApiKeyCredential _keyCredential; - private const string AuthorizationApiKeyPrefix = "Bearer"; - private readonly ClientPipeline _pipeline; - private readonly Uri _endpoint; - - public virtual ClientPipeline Pipeline => _pipeline; - - protected BatchClient() - { - } - - internal virtual CreateBatchOperation CreateBatchOperation(string batchId, string status, PipelineResponse response) +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace OpenAI.Batch +{ + // Data plane generated sub-client. + public partial class BatchClient + { + private const string AuthorizationHeader = "Authorization"; + private readonly ApiKeyCredential _keyCredential; + private const string AuthorizationApiKeyPrefix = "Bearer"; + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + public virtual ClientPipeline Pipeline => _pipeline; + + protected BatchClient() { - return new CreateBatchOperation(_pipeline, _endpoint, batchId, status, response); - } - - internal virtual PipelineMessage CreateCreateBatchRequest(BinaryContent content, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "POST"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/batches", false); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - request.Headers.Set("Content-Type", "application/json"); - request.Content = content; - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateGetBatchesRequest(string after, int? limit, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/batches", false); - if (after != null) - { - uri.AppendQuery("after", after, true); - } - if (limit != null) - { - uri.AppendQuery("limit", limit.Value, true); - } - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/batches/", false); - uri.AppendPath(batchId, true); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "POST"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/batches/", false); - uri.AppendPath(batchId, true); - uri.AppendPath("/cancel", false); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - - private static PipelineMessageClassifier _pipelineMessageClassifier200; - private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); - } -} + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + } +} diff --git a/.dotnet/src/Generated/FineTuningClient.cs b/.dotnet/src/Generated/FineTuningClient.cs index 555ffad20..ac5c8da64 100644 --- a/.dotnet/src/Generated/FineTuningClient.cs +++ b/.dotnet/src/Generated/FineTuningClient.cs @@ -1,98 +1,104 @@ -// - -#nullable disable - -using System; -using System.ClientModel; -using System.ClientModel.Primitives; -using System.Threading.Tasks; - -namespace OpenAI.FineTuning -{ - // Data plane generated sub-client. - public partial class FineTuningClient - { - private const string AuthorizationHeader = "Authorization"; - private readonly ApiKeyCredential _keyCredential; - private const string AuthorizationApiKeyPrefix = "Bearer"; - private readonly ClientPipeline _pipeline; - private readonly Uri _endpoint; - - public virtual ClientPipeline Pipeline => _pipeline; - - protected FineTuningClient() - { - } - - internal FineTuningClient(ClientPipeline pipeline, ApiKeyCredential keyCredential, Uri endpoint) - { - _pipeline = pipeline; - _keyCredential = keyCredential; - _endpoint = endpoint; - } - - internal virtual CreateJobOperation CreateJobOperation(string jobId, string status, PipelineResponse response) +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Threading.Tasks; + +namespace OpenAI.FineTuning +{ + // Data plane generated sub-client. + public partial class FineTuningClient + { + private const string AuthorizationHeader = "Authorization"; + private readonly ApiKeyCredential _keyCredential; + private const string AuthorizationApiKeyPrefix = "Bearer"; + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + public virtual ClientPipeline Pipeline => _pipeline; + + protected FineTuningClient() { - return new CreateJobOperation(_pipeline, _endpoint, jobId, status, response); - } - - internal virtual PipelineMessage CreateCreateFineTuningJobRequest(BinaryContent content, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "POST"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/fine_tuning/jobs", false); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - request.Headers.Set("Content-Type", "application/json"); - request.Content = content; - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateGetPaginatedFineTuningJobsRequest(string after, int? limit, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/fine_tuning/jobs", false); - if (after != null) - { - uri.AppendQuery("after", after, true); - } - if (limit != null) - { - uri.AppendQuery("limit", limit.Value, true); - } - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateRetrieveFineTuningJobRequest(string fineTuningJobId, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/fine_tuning/jobs/", false); - uri.AppendPath(fineTuningJobId, true); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - - private static PipelineMessageClassifier _pipelineMessageClassifier200; - private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); - } -} + } + + internal FineTuningClient(ClientPipeline pipeline, ApiKeyCredential keyCredential, Uri endpoint) + { + _pipeline = pipeline; + _keyCredential = keyCredential; + _endpoint = endpoint; + } + + internal PipelineMessage CreateCancelFineTuningJobRequest(string fineTuningJobId, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/fine_tuning/jobs/", false); + uri.AppendPath(fineTuningJobId, true); + uri.AppendPath("/cancel", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } + + internal PipelineMessage CreateGetFineTuningJobCheckpointsRequest(string fineTuningJobId, string after, int? limit, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/fine_tuning/jobs/", false); + uri.AppendPath(fineTuningJobId, true); + uri.AppendPath("/checkpoints", false); + if (after != null) + { + uri.AppendQuery("after", after, true); + } + if (limit != null) + { + uri.AppendQuery("limit", limit.Value, true); + } + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } + + internal PipelineMessage CreateGetFineTuningEventsRequest(string fineTuningJobId, string after, int? limit, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/fine_tuning/jobs/", false); + uri.AppendPath(fineTuningJobId, true); + uri.AppendPath("/events", false); + if (after != null) + { + uri.AppendQuery("after", after, true); + } + if (limit != null) + { + uri.AppendQuery("limit", limit.Value, true); + } + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + } +} diff --git a/.dotnet/src/Generated/VectorStoreClient.cs b/.dotnet/src/Generated/VectorStoreClient.cs index 7b0bcc359..b9436c5b7 100644 --- a/.dotnet/src/Generated/VectorStoreClient.cs +++ b/.dotnet/src/Generated/VectorStoreClient.cs @@ -78,23 +78,6 @@ internal PipelineMessage CreateGetVectorStoresRequest(int? limit, string order, return message; } - internal PipelineMessage CreateCreateVectorStoreRequest(BinaryContent content, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "POST"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/vector_stores", false); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - request.Headers.Set("Content-Type", "application/json"); - request.Content = content; - message.Apply(options); - return message; - } - internal PipelineMessage CreateGetVectorStoreRequest(string vectorStoreId, RequestOptions options) { var message = _pipeline.CreateMessage(); @@ -201,24 +184,6 @@ internal PipelineMessage CreateCreateVectorStoreFileRequest(string vectorStoreId return message; } - internal PipelineMessage CreateGetVectorStoreFileRequest(string vectorStoreId, string fileId, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/vector_stores/", false); - uri.AppendPath(vectorStoreId, true); - uri.AppendPath("/files/", false); - uri.AppendPath(fileId, true); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - internal PipelineMessage CreateDeleteVectorStoreFileRequest(string vectorStoreId, string fileId, RequestOptions options) { var message = _pipeline.CreateMessage(); @@ -237,43 +202,6 @@ internal PipelineMessage CreateDeleteVectorStoreFileRequest(string vectorStoreId return message; } - internal PipelineMessage CreateCreateVectorStoreFileBatchRequest(string vectorStoreId, BinaryContent content, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "POST"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/vector_stores/", false); - uri.AppendPath(vectorStoreId, true); - uri.AppendPath("/file_batches", false); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - request.Headers.Set("Content-Type", "application/json"); - request.Content = content; - message.Apply(options); - return message; - } - - internal PipelineMessage CreateGetVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/vector_stores/", false); - uri.AppendPath(vectorStoreId, true); - uri.AppendPath("/file_batches/", false); - uri.AppendPath(batchId, true); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - internal PipelineMessage CreateCancelVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestOptions options) { var message = _pipeline.CreateMessage(); From 5a08b12fcacf421c326775c0ff903ddcb4c22542 Mon Sep 17 00:00:00 2001 From: chschrae Date: Tue, 10 Sep 2024 12:20:07 -0700 Subject: [PATCH 05/18] PR nits --- .dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs | 4 ++-- .../VectorStores/CreateVectorStoreOperation.Protocol.cs | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs b/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs index 917344f8a..ae6cb0e6b 100644 --- a/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs +++ b/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs @@ -38,7 +38,7 @@ public partial class FineTuningClient /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// Service returned a non-success status code. - /// A that can be used to wait for + /// A that can be used to wait for /// the operation to complete, get information about the fine tuning job, or /// cancel the operation. public virtual async Task CreateJobAsync( @@ -77,7 +77,7 @@ public virtual async Task CreateJobAsync( /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// Service returned a non-success status code. - /// A that can be used to wait for + /// A that can be used to wait for /// the operation to complete, get information about the fine tuning job, or /// cancel the operation. public virtual CreateJobOperation CreateJob( diff --git a/.dotnet/src/Custom/VectorStores/CreateVectorStoreOperation.Protocol.cs b/.dotnet/src/Custom/VectorStores/CreateVectorStoreOperation.Protocol.cs index 44fe10a05..0068dfc3d 100644 --- a/.dotnet/src/Custom/VectorStores/CreateVectorStoreOperation.Protocol.cs +++ b/.dotnet/src/Custom/VectorStores/CreateVectorStoreOperation.Protocol.cs @@ -1,10 +1,7 @@ -using OpenAI.Batch; -using System; +using System; using System.ClientModel; using System.ClientModel.Primitives; using System.ComponentModel; -using System.Text.Json; -using System.Threading; using System.Threading.Tasks; #nullable enable From a269210c3290cf2e2c166c09e77d50bd8ac80b34 Mon Sep 17 00:00:00 2001 From: chschrae Date: Wed, 11 Sep 2024 11:13:26 -0700 Subject: [PATCH 06/18] removed EBN for internal methods --- .dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs b/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs index 10c0d13e3..648135aa8 100644 --- a/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs +++ b/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs @@ -144,7 +144,6 @@ public virtual CreateVectorStoreOperation CreateVectorStore(BinaryContent conten /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - [EditorBrowsable(EditorBrowsableState.Never)] internal virtual async Task GetVectorStoreAsync(string vectorStoreId, RequestOptions options) { Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); @@ -162,7 +161,6 @@ internal virtual async Task GetVectorStoreAsync(string vectorStore /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - [EditorBrowsable(EditorBrowsableState.Never)] internal virtual ClientResult GetVectorStore(string vectorStoreId, RequestOptions options) { Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); @@ -535,7 +533,6 @@ public virtual CreateBatchFileJobOperation CreateBatchFileJob( /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - [EditorBrowsable(EditorBrowsableState.Never)] internal virtual async Task GetBatchFileJobAsync(string vectorStoreId, string batchId, RequestOptions options) { Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); @@ -555,7 +552,6 @@ internal virtual async Task GetBatchFileJobAsync(string vectorStor /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - [EditorBrowsable(EditorBrowsableState.Never)] internal virtual ClientResult GetBatchFileJob(string vectorStoreId, string batchId, RequestOptions options) { Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); From 1e93130cba69b5e56d6372a6b83bf03d4f9f5bfb Mon Sep 17 00:00:00 2001 From: chschrae Date: Wed, 11 Sep 2024 11:34:04 -0700 Subject: [PATCH 07/18] fixing some merge build errors --- .../src/Custom/Batch/BatchClient.Protocol.cs | 1 + .dotnet/src/Custom/Batch/BatchClient.cs | 206 +++++++++--------- .../FineTuning/FineTuningClient.Protocol.cs | 1 + .../src/Custom/FineTuning/FineTuningClient.cs | 10 +- .../Custom/VectorStores/VectorStoreClient.cs | 16 +- ...orStoreFileAssociationCollectionOptions.cs | 5 + 6 files changed, 114 insertions(+), 125 deletions(-) diff --git a/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs b/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs index 9dab06239..bc8dc2a4e 100644 --- a/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs +++ b/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs @@ -1,6 +1,7 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using System.Threading.Tasks; diff --git a/.dotnet/src/Custom/Batch/BatchClient.cs b/.dotnet/src/Custom/Batch/BatchClient.cs index d303d4e4e..e6add4633 100644 --- a/.dotnet/src/Custom/Batch/BatchClient.cs +++ b/.dotnet/src/Custom/Batch/BatchClient.cs @@ -2,16 +2,16 @@ using System.ClientModel; using System.ClientModel.Primitives; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace OpenAI.Batch; -// CUSTOM: -// - Renamed. -// - Suppressed constructor that takes endpoint parameter; endpoint is now a property in the options class. -// - Suppressed convenience methods for now. -/// The service client for OpenAI batch operations. -[Experimental("OPENAI001")] +// CUSTOM: +// - Renamed. +// - Suppressed constructor that takes endpoint parameter; endpoint is now a property in the options class. +// - Suppressed convenience methods for now. +/// The service client for OpenAI batch operations. +[Experimental("OPENAI001")] [CodeGenClient("Batches")] [CodeGenSuppress("BatchClient", typeof(ClientPipeline), typeof(ApiKeyCredential), typeof(Uri))] [CodeGenSuppress("CreateBatch", typeof(string), typeof(InternalCreateBatchRequestEndpoint), typeof(InternalBatchCompletionTimeframe), typeof(IDictionary))] @@ -37,108 +37,106 @@ public partial class BatchClient /// Additional options to customize the client. /// The provided was null. public BatchClient(ApiKeyCredential credential, OpenAIClientOptions options = null) - : this( - OpenAIClient.CreatePipeline(OpenAIClient.GetApiKey(credential, requireExplicitCredential: true), options), - OpenAIClient.GetEndpoint(options), - options) - { } + { + Argument.AssertNotNull(credential, nameof(credential)); + options ??= new OpenAIClientOptions(); - _pipeline = OpenAIClient.CreatePipeline(credential, options); - _endpoint = OpenAIClient.GetEndpoint(options); - } + _pipeline = OpenAIClient.CreatePipeline(credential, options); + _endpoint = OpenAIClient.GetEndpoint(options); + } - // CUSTOM: - // - Used a custom pipeline. - // - Demoted the endpoint parameter to be a property in the options class. - // - Made protected. - /// Initializes a new instance of . - /// The HTTP pipeline to send and receive REST requests and responses. - /// The options to configure the client. - /// is null. - protected internal BatchClient(ClientPipeline pipeline, OpenAIClientOptions options) + // CUSTOM: + // - Used a custom pipeline. + // - Demoted the endpoint parameter to be a property in the options class. + // - Made protected. + /// Initializes a new instance of . + /// The HTTP pipeline to send and receive REST requests and responses. + /// The options to configure the client. + /// is null. + protected internal BatchClient(ClientPipeline pipeline, OpenAIClientOptions options) { - Argument.AssertNotNull(pipeline, nameof(pipeline)); - options ??= new OpenAIClientOptions(); - + Argument.AssertNotNull(pipeline, nameof(pipeline)); + options ??= new OpenAIClientOptions(); + _pipeline = pipeline; - _endpoint = OpenAIClient.GetEndpoint(options); - } - - internal virtual CreateBatchOperation CreateCreateBatchOperation(string batchId, string status, PipelineResponse response) - { - return new CreateBatchOperation(_pipeline, _endpoint, batchId, status, response); + _endpoint = OpenAIClient.GetEndpoint(options); + } + + internal virtual CreateBatchOperation CreateCreateBatchOperation(string batchId, string status, PipelineResponse response) + { + return new CreateBatchOperation(_pipeline, _endpoint, batchId, status, response); + } + + internal virtual PipelineMessage CreateCreateBatchRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/batches", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateGetBatchesRequest(string after, int? limit, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/batches", false); + if (after != null) + { + uri.AppendQuery("after", after, true); + } + if (limit != null) + { + uri.AppendQuery("limit", limit.Value, true); + } + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; } - internal virtual PipelineMessage CreateCreateBatchRequest(BinaryContent content, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "POST"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/batches", false); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - request.Headers.Set("Content-Type", "application/json"); - request.Content = content; - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateGetBatchesRequest(string after, int? limit, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/batches", false); - if (after != null) - { - uri.AppendQuery("after", after, true); - } - if (limit != null) - { - uri.AppendQuery("limit", limit.Value, true); - } - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/batches/", false); - uri.AppendPath(batchId, true); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "POST"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/batches/", false); - uri.AppendPath(batchId, true); - uri.AppendPath("/cancel", false); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; + internal virtual PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/batches/", false); + uri.AppendPath(batchId, true); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/batches/", false); + uri.AppendPath(batchId, true); + uri.AppendPath("/cancel", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; } } diff --git a/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs b/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs index e3d5e6203..2cd48bb8d 100644 --- a/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs +++ b/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs @@ -1,6 +1,7 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using System.Threading.Tasks; diff --git a/.dotnet/src/Custom/FineTuning/FineTuningClient.cs b/.dotnet/src/Custom/FineTuning/FineTuningClient.cs index 63518f3b9..55fe1f53f 100644 --- a/.dotnet/src/Custom/FineTuning/FineTuningClient.cs +++ b/.dotnet/src/Custom/FineTuning/FineTuningClient.cs @@ -45,12 +45,10 @@ public partial class FineTuningClient /// The API key used to authenticate with the service endpoint. /// Additional options to customize the client. /// The provided was null. - public FineTuningClient(ApiKeyCredential credential, OpenAIClientOptions options = null) - : this( - OpenAIClient.CreatePipeline(OpenAIClient.GetApiKey(credential, requireExplicitCredential: true), options), - OpenAIClient.GetEndpoint(options), - options) - { } + public FineTuningClient(ApiKeyCredential credential, OpenAIClientOptions options = null) + { + Argument.AssertNotNull(credential, nameof(credential)); + options ??= new OpenAIClientOptions(); _pipeline = OpenAIClient.CreatePipeline(credential, options); _endpoint = OpenAIClient.GetEndpoint(options); diff --git a/.dotnet/src/Custom/VectorStores/VectorStoreClient.cs b/.dotnet/src/Custom/VectorStores/VectorStoreClient.cs index 3c12b7fab..6678c7b1a 100644 --- a/.dotnet/src/Custom/VectorStores/VectorStoreClient.cs +++ b/.dotnet/src/Custom/VectorStores/VectorStoreClient.cs @@ -51,21 +51,7 @@ public partial class VectorStoreClient /// The API key used to authenticate with the service endpoint. /// Additional options to customize the client. /// The provided was null. - public VectorStoreClient(ApiKeyCredential credential, OpenAIClientOptions options = null) - : this( - OpenAIClient.CreatePipeline(OpenAIClient.GetApiKey(credential, requireExplicitCredential: true), options), - OpenAIClient.GetEndpoint(options), - options) - { } - - // CUSTOM: - // - Used a custom pipeline. - // - Demoted the endpoint parameter to be a property in the options class. - /// Initializes a new instance of . - /// The API key to authenticate with the service. - /// The options to configure the client. - /// is null. - public VectorStoreClient(ApiKeyCredential credential, OpenAIClientOptions options) + public VectorStoreClient(ApiKeyCredential credential, OpenAIClientOptions options = null) { Argument.AssertNotNull(credential, nameof(credential)); options ??= new OpenAIClientOptions(); diff --git a/.dotnet/src/Custom/VectorStores/VectorStoreFileAssociationCollectionOptions.cs b/.dotnet/src/Custom/VectorStores/VectorStoreFileAssociationCollectionOptions.cs index 71b2a8b0c..34c3c22df 100644 --- a/.dotnet/src/Custom/VectorStores/VectorStoreFileAssociationCollectionOptions.cs +++ b/.dotnet/src/Custom/VectorStores/VectorStoreFileAssociationCollectionOptions.cs @@ -20,6 +20,11 @@ public VectorStoreFileAssociationCollectionOptions() { } /// public VectorStoreFileAssociationCollectionOrder? Order { get; set; } + /// + /// The number of values to return in a page result. + /// + public int? PageSize { get; set; } + /// /// The used to retrieve the page of objects that come /// after this one. From b937a54b61e148226a5c67acba06054dd8b30f80 Mon Sep 17 00:00:00 2001 From: chschrae Date: Thu, 12 Sep 2024 08:58:57 -0700 Subject: [PATCH 08/18] updated batch and vector store tests --- .../Azure.AI.OpenAI/tests/BatchTests.cs | 12 +++--- .../Azure.AI.OpenAI/tests/VectorStoreTests.cs | 42 +++++++++++-------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/BatchTests.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/BatchTests.cs index 357c022d1..aa1a2ef66 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/BatchTests.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/BatchTests.cs @@ -56,15 +56,13 @@ public async Task SimpleBatchCompletionsTest() } }.ToBinaryContent(); - ClientResult response = await batchClient.CreateBatchAsync(requestContent); - BatchObject batchObj = ExtractAndValidateBatchObj(response); + CreateBatchOperation operation = await batchClient.CreateBatchAsync(requestContent, true); // Poll until we've completed, failed, or were canceled - while ("completed" != batchObj.Status) - { - response = await batchClient.GetBatchAsync(batchObj.Id, new()); - batchObj = ExtractAndValidateBatchObj(response); - } + operation.WaitForCompletion(); + + ClientResult response = operation.GetBatch(null); + BatchObject batchObj = ExtractAndValidateBatchObj(response); Assert.That(batchObj.OutputFileID, Is.Not.Null.Or.Empty); BinaryData outputData = await ops.DownloadAndValidateResultAsync(batchObj.OutputFileID!); diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs index 2365e0f19..05a518451 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs @@ -37,14 +37,14 @@ public async Task CanCreateGetAndDeleteVectorStores() { VectorStoreClient client = GetTestClient(); - VectorStore vectorStore = await client.CreateVectorStoreAsync(); - Validate(vectorStore); - bool deleted = await client.DeleteVectorStoreAsync(vectorStore); + CreateVectorStoreOperation createVectorStoreOperation = await client.CreateVectorStoreAsync(false); + Validate(createVectorStoreOperation); + bool deleted = await client.DeleteVectorStoreAsync(createVectorStoreOperation.GetVectorStore()); Assert.That(deleted, Is.True); IReadOnlyList testFiles = await GetNewTestFilesAsync(client.GetConfigOrThrow(), 5); - vectorStore = await client.CreateVectorStoreAsync(new VectorStoreCreationOptions() + createVectorStoreOperation = await client.CreateVectorStoreAsync(false, new VectorStoreCreationOptions() { FileIds = { testFiles[0].Id }, Name = "test vector store", @@ -58,7 +58,8 @@ public async Task CanCreateGetAndDeleteVectorStores() ["test-key"] = "test-value", }, }); - Validate(vectorStore); + Validate(createVectorStoreOperation); + VectorStore vectorStore = createVectorStoreOperation.GetVectorStore(); Assert.Multiple(() => { Assert.That(vectorStore.Name, Is.EqualTo("test vector store")); @@ -70,7 +71,7 @@ public async Task CanCreateGetAndDeleteVectorStores() Assert.That(vectorStore.Status, Is.EqualTo(VectorStoreStatus.InProgress)); Assert.That(vectorStore.Metadata?.TryGetValue("test-key", out string metadataValue) == true && metadataValue == "test-value"); }); - vectorStore = await client.GetVectorStoreAsync(vectorStore); + vectorStore = createVectorStoreOperation.GetVectorStore(); Assert.Multiple(() => { Assert.That(vectorStore.Name, Is.EqualTo("test vector store")); @@ -85,10 +86,12 @@ public async Task CanCreateGetAndDeleteVectorStores() deleted = await client.DeleteVectorStoreAsync(vectorStore.Id); Assert.That(deleted, Is.True); - vectorStore = await client.CreateVectorStoreAsync(new VectorStoreCreationOptions() + createVectorStoreOperation = await client.CreateVectorStoreAsync(false, new VectorStoreCreationOptions() { FileIds = testFiles.Select(file => file.Id).ToList() }); + + vectorStore = createVectorStoreOperation.GetVectorStore(); Validate(vectorStore); Assert.Multiple(() => { @@ -103,10 +106,13 @@ public async Task CanEnumerateVectorStores() VectorStoreClient client = GetTestClient(); for (int i = 0; i < 10; i++) { - VectorStore vectorStore = await client.CreateVectorStoreAsync(new VectorStoreCreationOptions() + CreateVectorStoreOperation createVectorStoreOperation = await client.CreateVectorStoreAsync( + false, + new VectorStoreCreationOptions() { Name = $"Test Vector Store {i}", }); + VectorStore vectorStore = createVectorStoreOperation.GetVectorStore(); Validate(vectorStore); Assert.That(vectorStore.Name, Is.EqualTo($"Test Vector Store {i}")); } @@ -140,14 +146,16 @@ public async Task CanEnumerateVectorStores() public async Task CanAssociateFiles() { VectorStoreClient client = GetTestClient(); - VectorStore vectorStore = await client.CreateVectorStoreAsync(); + CreateVectorStoreOperation createVectorStoreOperation = await client.CreateVectorStoreAsync(false); + VectorStore vectorStore = createVectorStoreOperation.GetVectorStore(); Validate(vectorStore); IReadOnlyList files = await GetNewTestFilesAsync(client.GetConfigOrThrow(), 3); foreach (OpenAIFileInfo file in files) { - VectorStoreFileAssociation association = await client.AddFileToVectorStoreAsync(vectorStore, file); + AddFileToVectorStoreOperation addFileToVectorStoreOperation = await client.AddFileToVectorStoreAsync(vectorStore, file, false); + VectorStoreFileAssociation association = addFileToVectorStoreOperation.GetFileAssociation(); Validate(association); Assert.Multiple(() => { @@ -181,12 +189,14 @@ public async Task CanAssociateFiles() public async Task CanUseBatchIngestion() { VectorStoreClient client = GetTestClient(); - VectorStore vectorStore = await client.CreateVectorStoreAsync(); + CreateVectorStoreOperation createVectorStoreOperation = await client.CreateVectorStoreAsync(false); + VectorStore vectorStore = createVectorStoreOperation.GetVectorStore(); Validate(vectorStore); IReadOnlyList testFiles = await GetNewTestFilesAsync(client.GetConfigOrThrow(), 3); - VectorStoreBatchFileJob batchJob = await client.CreateBatchFileJobAsync(vectorStore, testFiles); + CreateBatchFileJobOperation createBatchFileJobOperation = await client.CreateBatchFileJobAsync(vectorStore, testFiles, false); + VectorStoreBatchFileJob batchJob = createBatchFileJobOperation.GetFileBatch(); Assert.Multiple(() => { Assert.That(batchJob.BatchId, Is.Not.Null); @@ -194,13 +204,11 @@ public async Task CanUseBatchIngestion() Assert.That(batchJob.Status, Is.EqualTo(VectorStoreBatchFileJobStatus.InProgress)); }); - batchJob = await WaitUntilReturnLast( - batchJob, - () => client.GetBatchFileJobAsync(batchJob), - b => b.Status != VectorStoreBatchFileJobStatus.InProgress); + createBatchFileJobOperation.WaitForCompletion(); + batchJob = createBatchFileJobOperation.GetFileBatch(); Assert.That(batchJob.Status, Is.EqualTo(VectorStoreBatchFileJobStatus.Completed)); - AsyncPageCollection response = client.GetFileAssociationsAsync(batchJob); + AsyncPageCollection response = client.GetFileAssociationsAsync(vectorStore); await foreach (VectorStoreFileAssociation association in response.GetAllValuesAsync()) { Assert.Multiple(() => From cea2130648f3f96780aca12ce11d2bb1293f16b1 Mon Sep 17 00:00:00 2001 From: chschrae Date: Tue, 17 Sep 2024 10:40:01 -0700 Subject: [PATCH 09/18] updated tests and fixed CreateJob functions to call internal factory --- .../AzureCreateJobOperation.Protocol.cs | 4 +- .../AzureFineTuningClient.Protocol.cs | 18 ++++ .../Azure.AI.OpenAI/tests/FineTuningTests.cs | 98 ++++++++----------- .../src/Custom/Batch/BatchClient.Protocol.cs | 4 +- .../FineTuning/CreateJobOperation.Protocol.cs | 12 +-- .../FineTuning/FineTuningClient.Protocol.cs | 4 +- .../VectorStoreClient.Protocol.cs | 12 +-- 7 files changed, 75 insertions(+), 77 deletions(-) diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs index d7c4caec0..02af08875 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs @@ -73,7 +73,7 @@ internal override PipelineMessage CreateCancelFineTuningJobRequest(string fineTu .WithOptions(options) .Build(); - internal override PipelineMessage CreateGetFineTuningJobCheckpointsRequest(string fineTuningJobId, string after, int? limit, RequestOptions? options) + internal override PipelineMessage CreateGetFineTuningJobCheckpointsRequest(string fineTuningJobId, string? after, int? limit, RequestOptions? options) => new AzureOpenAIPipelineMessageBuilder(_pipeline, _endpoint, _apiVersion) .WithMethod("GET") .WithPath("fine_tuning", "jobs", fineTuningJobId, "checkpoints") @@ -83,7 +83,7 @@ internal override PipelineMessage CreateGetFineTuningJobCheckpointsRequest(strin .WithOptions(options) .Build(); - internal override PipelineMessage CreateGetFineTuningEventsRequest(string fineTuningJobId, string after, int? limit, RequestOptions? options) + internal override PipelineMessage CreateGetFineTuningEventsRequest(string fineTuningJobId, string? after, int? limit, RequestOptions? options) => new AzureOpenAIPipelineMessageBuilder(_pipeline, _endpoint, _apiVersion) .WithMethod("GET") .WithPath("fine_tuning", "jobs", fineTuningJobId, "events") diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs index 62985c14e..98353c64e 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs @@ -3,9 +3,27 @@ using System.ClientModel; using System.ClientModel.Primitives; +using System.Text.Json; namespace Azure.AI.OpenAI.FineTuning; internal partial class AzureFineTuningClient : FineTuningClient { + public override async Task CreateJobAsync( + BinaryContent content, + bool waitUntilCompleted, + RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateCreateFineTuningJobRequest(content, options); + PipelineResponse response = await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); + + using JsonDocument doc = JsonDocument.Parse(response.Content); + string jobId = doc.RootElement.GetProperty("id"u8).GetString(); + string status = doc.RootElement.GetProperty("status"u8).GetString(); + + AzureCreateJobOperation operation = new(Pipeline, _endpoint, jobId, status, response, _apiVersion); + return await operation.WaitUntilAsync(waitUntilCompleted, options).ConfigureAwait(false); + } } diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs index dcd559eb7..2b652bc63 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs @@ -22,7 +22,7 @@ namespace Azure.AI.OpenAI.Tests; public class FineTuningTests : AoaiTestBase { - public FineTuningTests(bool isAsync) : base(isAsync) + public FineTuningTests(bool isAsync) : base(isAsync, RecordedTestMode.Live) { } [Test] @@ -51,7 +51,7 @@ public async Task JobsFineTuning() } } - [RecordedTest] + [RecordedTest] public async Task CheckpointsFineTuning() { string fineTunedModel = GetFineTunedModel(); @@ -91,17 +91,24 @@ public async Task EventsFineTuning() { string fineTunedModel = GetFineTunedModel(); FineTuningClient client = GetTestClient(); - // Check if the model exists by searching all jobs FineTuningJob job = await EnumerateJobsAsync(client) .FirstOrDefaultAsync(j => j.FineTunedModel == fineTunedModel)!; + Assert.That(job, Is.Not.Null); Assert.That(job!.Status, Is.EqualTo("succeeded")); HashSet ids = new(); int count = 25; - var asyncEnum = EnumerateAsync((after, limit, opt) => client.GetJobEventsAsync(job.ID, after, limit, opt)); + var asyncEnum = EnumerateAsync((after, limit, opt) => + { + var jobIdBinaryString = $"{{\"jobId\":\"{job.ID}\"}}"; + var createdToken = ContinuationToken.FromBytes(BinaryData.FromString(jobIdBinaryString)); + CreateJobOperation operation = CreateJobOperation.Rehydrate(client, createdToken); + return (IAsyncEnumerable)operation.GetJobEvents(after, limit, opt); + + }); await foreach (FineTuningJobEvent evt in asyncEnum) { if (count-- <= 0) @@ -121,18 +128,6 @@ public async Task EventsFineTuning() } } - [RecordedTest] - public async Task DeleteFineTuningModel() - { - FineTuningClient client = GetTestClient(); - Assert.That(client, Is.Not.Null); - Assert.That(client, Is.InstanceOf()); - - // The service always happily returns HTTP 204 regardless of whether or not the model exists - bool deleted = await DeleteJobAndVerifyAsync(client, "does-not-exist"); - Assert.That(deleted, Is.True); - } - [RecordedTest] public async Task CreateAndCancelFineTuning() { @@ -143,7 +138,6 @@ public async Task CreateAndCancelFineTuning() // upload training data OpenAIFileInfo uploadedFile = await UploadAndWaitForCompleteOrFail(fileClient, fineTuningFile.RelativePath); - // Create the fine tuning job using var requestContent = new FineTuningOptions() { @@ -151,22 +145,24 @@ public async Task CreateAndCancelFineTuning() TrainingFile = uploadedFile.Id }.ToBinaryContent(); - ClientResult result = await client.CreateJobAsync(requestContent); - FineTuningJob job = ValidateAndParse(result); + //TODO handle synchronous versions of operations + CreateJobOperation operation = await client.CreateJobAsync(requestContent, new()); + var jobFromResult = await operation.GetJobAsync(null); + FineTuningJob job = ValidateAndParse(jobFromResult); Assert.That(job.ID, !(Is.Null.Or.Empty)); - await using RunOnScopeExit _ = new(async () => { - bool deleted = await DeleteJobAndVerifyAsync(client, job.ID); + bool deleted = await DeleteJobAndVerifyAsync((AzureCreateJobOperation)operation, job.ID); Assert.True(deleted, "Failed to delete fine tuning job: {0}", job.ID); }); - // Wait for some events to become available - ListResponse events; + //Wait for some events to become available + ClientResult result; + ListResponse < FineTuningJobEvent > events; int maxLoops = 10; do { - result = await client.GetJobEventsAsync(job.ID, null, 10, new()).FirstOrDefaultAsync(); + result = await operation.GetJobEventsAsync(null, 10, new()); events = ValidateAndParse>(result); if (events.Data?.Count > 0) @@ -185,12 +181,12 @@ public async Task CreateAndCancelFineTuning() } while (maxLoops-- > 0); // Cancel the fine tuning job - result = await client.CancelJobAsync(job.ID, new()); + result = await operation.CancelAsync(null); job = ValidateAndParse(result); // Make sure the job status shows as cancelled - job = await WaitForJobToEnd(client, job); - Assert.That(job.Status, Is.EqualTo("cancelled")); + await operation.WaitForCompletionAsync(); + Assert.True(operation.HasCompleted); } [RecordedTest(AutomaticRecord = false)] @@ -213,19 +209,20 @@ public async Task CreateAndDeleteFineTuning() TrainingFile = uploadedFile.Id }.ToBinaryContent(); - ClientResult result = await client.CreateJobAsync(requestContent); - FineTuningJob job = ValidateAndParse(result); + CreateJobOperation operation = await client.CreateJobAsync(requestContent, false); + FineTuningJob job = ValidateAndParse(await operation.GetJobAsync(null)); Assert.That(job.ID, Is.Not.Null.Or.Empty); Assert.That(job.Error, Is.Null); Assert.That(job.Status, !(Is.Null.Or.EqualTo("failed").Or.EqualTo("cancelled"))); // Wait for the fine tuning to complete - job = await WaitForJobToEnd(client, job); + await operation.WaitForCompletionAsync(); + job = ValidateAndParse(await operation.GetJobAsync(null)); Assert.That(job.Status, Is.EqualTo("succeeded"), "Fine tuning did not succeed"); Assert.That(job.FineTunedModel, Is.Not.Null.Or.Empty); // Delete the fine tuned model - bool deleted = await DeleteJobAndVerifyAsync(client, job.ID); + bool deleted = await DeleteJobAndVerifyAsync((AzureCreateJobOperation)operation, job.ID); Assert.True(deleted, "Failed to delete fine tuning model: {0}", job.FineTunedModel); } @@ -332,29 +329,17 @@ private async Task UploadAndWaitForCompleteOrFail(FileClient fil return uploadedFile; } - private Task WaitForJobToEnd(FineTuningClient client, FineTuningJob job) - { - RequestOptions options = new(); - string jobId = job.ID; - - // NOTE: Fine tuning jobs can take up 30 minutes to complete so the timeouts here are longer to account for that - return WaitUntilReturnLast( - job, - async () => - { - ClientResult result = await client.GetJobAsync(jobId, options).ConfigureAwait(false); - return ValidateAndParse(result); - }, - j => j.Status == "cancelled" || j.Status == "failed" || j.Status == "succeeded", - TimeSpan.FromMinutes(1), - TimeSpan.FromMinutes(40)); - } - private IAsyncEnumerable EnumerateJobsAsync(FineTuningClient client) => EnumerateAsync((after, limit, opt) => client.GetJobsAsync(after, limit, opt)); private IAsyncEnumerable EnumerateCheckpoints(FineTuningClient client, string jobId) - => EnumerateAsync((after, limit, opt) => client.GetJobCheckpointsAsync(jobId, after, limit, opt)); + => EnumerateAsync((after, limit, opt) => + { + var jobIdBinaryString = $"{{\"jobId\":\"{jobId}\"}}"; + var createdToken = ContinuationToken.FromBytes(BinaryData.FromString(jobIdBinaryString)); + CreateJobOperation operation = CreateJobOperation.Rehydrate(client, createdToken); + return (IAsyncEnumerable)operation.GetJobCheckpoints(after, limit, opt); + }); private async IAsyncEnumerable EnumerateAsync(Func> getAsyncEnumerable) where T : FineTuningModelBase @@ -375,7 +360,7 @@ private async IAsyncEnumerable EnumerateAsync(Func DeleteJobAndVerifyAsync(FineTuningClient client, string jobId, TimeSpan? timeBetween = null, TimeSpan? maxWaitTime = null) + private async Task DeleteJobAndVerifyAsync(AzureCreateJobOperation operation, string jobId, TimeSpan? timeBetween = null, TimeSpan? maxWaitTime = null) { var stopTime = DateTimeOffset.Now + (maxWaitTime ?? TimeSpan.FromMinutes(1)); var sleepTime = timeBetween ?? TimeSpan.FromSeconds(2); @@ -385,20 +370,15 @@ private async Task DeleteJobAndVerifyAsync(FineTuningClient client, string ErrorOptions = ClientErrorBehaviors.NoThrow }; - // Since the DeleteJob and DeleteJobAsync are extensions methods, we need to call them on the unwrapped type, - // instead of the dynamically wrapped type. - var rawClient = UnWrap(client); - bool success = false; while (DateTimeOffset.Now < stopTime) { ClientResult result = IsAsync - ? await rawClient.DeleteJobAsync(jobId, noThrow).ConfigureAwait(false) - : rawClient.DeleteJob(jobId, noThrow); + ? await operation.DeleteJobAsync(jobId, noThrow).ConfigureAwait(false) + : operation.DeleteJob(jobId, noThrow); Assert.That(result, Is.Not.Null); - // verify the deletion actually succeeded - result = await client.GetJobAsync(jobId, noThrow).ConfigureAwait(false); + result = await operation.GetJobAsync(noThrow).ConfigureAwait(false); var rawResponse = result.GetRawResponse(); success = rawResponse.Status == 404; if (success) diff --git a/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs b/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs index bc8dc2a4e..fa5894203 100644 --- a/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs +++ b/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs @@ -36,7 +36,7 @@ public virtual async Task CreateBatchAsync(BinaryContent c string batchId = doc.RootElement.GetProperty("id"u8).GetString(); string status = doc.RootElement.GetProperty("status"u8).GetString(); - CreateBatchOperation operation = new(_pipeline, _endpoint, batchId, status, response); + CreateBatchOperation operation = this.CreateCreateBatchOperation(batchId, status, response); return await operation.WaitUntilAsync(waitUntilCompleted, options).ConfigureAwait(false); } @@ -64,7 +64,7 @@ public virtual CreateBatchOperation CreateBatch(BinaryContent content, bool wait string batchId = doc.RootElement.GetProperty("id"u8).GetString(); string status = doc.RootElement.GetProperty("status"u8).GetString(); - CreateBatchOperation operation = new(_pipeline, _endpoint, batchId, status, response); + CreateBatchOperation operation = this.CreateCreateBatchOperation(batchId, status, response); return operation.WaitUntil(waitUntilCompleted, options); } diff --git a/.dotnet/src/Custom/FineTuning/CreateJobOperation.Protocol.cs b/.dotnet/src/Custom/FineTuning/CreateJobOperation.Protocol.cs index 3922f7f94..55cb8c59f 100644 --- a/.dotnet/src/Custom/FineTuning/CreateJobOperation.Protocol.cs +++ b/.dotnet/src/Custom/FineTuning/CreateJobOperation.Protocol.cs @@ -222,7 +222,7 @@ public virtual ClientResult Cancel(RequestOptions? options) /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// Service returned a non-success status code. /// The response returned from the service. - public virtual async Task GetJobEventsAsync(string after, int? limit, RequestOptions? options) + public virtual async Task GetJobEventsAsync(string? after, int? limit, RequestOptions? options) { using PipelineMessage message = CreateGetFineTuningEventsRequest(_jobId, after, limit, options); return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); @@ -239,7 +239,7 @@ public virtual async Task GetJobEventsAsync(string after, int? lim /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// Service returned a non-success status code. /// The response returned from the service. - public virtual ClientResult GetJobEvents(string after, int? limit, RequestOptions? options) + public virtual ClientResult GetJobEvents(string? after, int? limit, RequestOptions? options) { using PipelineMessage message = CreateGetFineTuningEventsRequest(_jobId, after, limit, options); return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); @@ -253,7 +253,7 @@ public virtual ClientResult GetJobEvents(string after, int? limit, RequestOption /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// Service returned a non-success status code. /// The response returned from the service. - public virtual async Task GetJobCheckpointsAsync(string after, int? limit, RequestOptions? options) + public virtual async Task GetJobCheckpointsAsync(string? after, int? limit, RequestOptions? options) { using PipelineMessage message = CreateGetFineTuningJobCheckpointsRequest(_jobId, after, limit, options); return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); @@ -267,7 +267,7 @@ public virtual async Task GetJobCheckpointsAsync(string after, int /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// Service returned a non-success status code. /// The response returned from the service. - public virtual ClientResult GetJobCheckpoints(string after, int? limit, RequestOptions? options) + public virtual ClientResult GetJobCheckpoints(string? after, int? limit, RequestOptions? options) { using PipelineMessage message = CreateGetFineTuningJobCheckpointsRequest(_jobId, after, limit, options); return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); @@ -306,7 +306,7 @@ internal virtual PipelineMessage CreateCancelFineTuningJobRequest(string fineTun return message; } - internal virtual PipelineMessage CreateGetFineTuningJobCheckpointsRequest(string fineTuningJobId, string after, int? limit, RequestOptions? options) + internal virtual PipelineMessage CreateGetFineTuningJobCheckpointsRequest(string fineTuningJobId, string? after, int? limit, RequestOptions? options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; @@ -331,7 +331,7 @@ internal virtual PipelineMessage CreateGetFineTuningJobCheckpointsRequest(string return message; } - internal virtual PipelineMessage CreateGetFineTuningEventsRequest(string fineTuningJobId, string after, int? limit, RequestOptions? options) + internal virtual PipelineMessage CreateGetFineTuningEventsRequest(string fineTuningJobId, string? after, int? limit, RequestOptions? options) { var message = _pipeline.CreateMessage(); message.ResponseClassifier = PipelineMessageClassifier200; diff --git a/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs b/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs index 2cd48bb8d..c61323716 100644 --- a/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs +++ b/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs @@ -56,7 +56,7 @@ public virtual async Task CreateJobAsync( string jobId = doc.RootElement.GetProperty("id"u8).GetString(); string status = doc.RootElement.GetProperty("status"u8).GetString(); - CreateJobOperation operation = new(_pipeline, _endpoint, jobId, status, response); + CreateJobOperation operation = this.CreateCreateJobOperation(jobId, status, response); return await operation.WaitUntilAsync(waitUntilCompleted, options).ConfigureAwait(false); } @@ -95,7 +95,7 @@ public virtual CreateJobOperation CreateJob( string jobId = doc.RootElement.GetProperty("id"u8).GetString(); string status = doc.RootElement.GetProperty("status"u8).GetString(); - CreateJobOperation operation = new(_pipeline, _endpoint, jobId, status, response); + CreateJobOperation operation = this.CreateCreateJobOperation(jobId, status, response); return operation.WaitUntil(waitUntilCompleted, options); } diff --git a/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs b/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs index 648135aa8..133f764de 100644 --- a/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs +++ b/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs @@ -107,7 +107,7 @@ public virtual async Task CreateVectorStoreAsync(Bin PipelineResponse response = await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); VectorStore value = VectorStore.FromResponse(response); - CreateVectorStoreOperation operation = new(_pipeline, _endpoint, ClientResult.FromValue(value, response)); + CreateVectorStoreOperation operation = this.CreateCreateVectorStoreOperation(ClientResult.FromValue(value, response)); return await operation.WaitUntilAsync(waitUntilCompleted, options).ConfigureAwait(false); } @@ -131,7 +131,7 @@ public virtual CreateVectorStoreOperation CreateVectorStore(BinaryContent conten PipelineResponse response = _pipeline.ProcessMessage(message, options); VectorStore value = VectorStore.FromResponse(response); - CreateVectorStoreOperation operation = new(_pipeline, _endpoint, ClientResult.FromValue(value, response)); + CreateVectorStoreOperation operation = this.CreateCreateVectorStoreOperation(ClientResult.FromValue(value, response)); return operation.WaitUntil(waitUntilCompleted, options); } @@ -344,7 +344,7 @@ public virtual async Task AddFileToVectorStoreAsy PipelineResponse response = await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); VectorStoreFileAssociation value = VectorStoreFileAssociation.FromResponse(response); - AddFileToVectorStoreOperation operation = new(_pipeline, _endpoint, ClientResult.FromValue(value, response)); + AddFileToVectorStoreOperation operation = this.CreateAddFileToVectorStoreOperation(ClientResult.FromValue(value, response)); return await operation.WaitUntilAsync(waitUntilCompleted, options).ConfigureAwait(false); } @@ -373,7 +373,7 @@ public virtual AddFileToVectorStoreOperation AddFileToVectorStore(string vectorS PipelineResponse response = _pipeline.ProcessMessage(message, options); VectorStoreFileAssociation value = VectorStoreFileAssociation.FromResponse(response); - AddFileToVectorStoreOperation operation = new(_pipeline, _endpoint, ClientResult.FromValue(value, response)); + AddFileToVectorStoreOperation operation = this.CreateAddFileToVectorStoreOperation(ClientResult.FromValue(value, response)); return operation.WaitUntil(waitUntilCompleted, options); } @@ -486,7 +486,7 @@ public virtual async Task CreateBatchFileJobAsync( PipelineResponse response = await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); VectorStoreBatchFileJob job = VectorStoreBatchFileJob.FromResponse(response); - CreateBatchFileJobOperation operation = new(_pipeline, _endpoint, ClientResult.FromValue(job, response)); + CreateBatchFileJobOperation operation = this.CreateBatchFileJobOperation(ClientResult.FromValue(job, response)); return await operation.WaitUntilAsync(waitUntilCompleted, options).ConfigureAwait(false); } @@ -519,7 +519,7 @@ public virtual CreateBatchFileJobOperation CreateBatchFileJob( PipelineResponse response = _pipeline.ProcessMessage(message, options); VectorStoreBatchFileJob job = VectorStoreBatchFileJob.FromResponse(response); - CreateBatchFileJobOperation operation = new(_pipeline, _endpoint, ClientResult.FromValue(job, response)); + CreateBatchFileJobOperation operation = this.CreateBatchFileJobOperation(ClientResult.FromValue(job, response)); return operation.WaitUntil(waitUntilCompleted, options); } From 46341dcd5b4f57c97841689f2b744dbfca2884e2 Mon Sep 17 00:00:00 2001 From: chschrae Date: Tue, 17 Sep 2024 10:53:43 -0700 Subject: [PATCH 10/18] PR nits and moved message builder methods to .Protocol files --- .../Custom/Batch/AzureBatchClient.Protocol.cs | 35 +++++++++ .../src/Custom/Batch/AzureBatchClient.cs | 35 --------- .../AzureFineTuningClient.Protocol.cs | 27 +++++++ .../FineTuning/AzureFineTuningClient.cs | 29 +------- .../AzureVectorStoreClient.Protocol.cs | 34 +++++++++ .../VectorStores/AzureVectorStoreClient.cs | 36 --------- .../src/Custom/Batch/BatchClient.Protocol.cs | 73 +++++++++++++++++++ .dotnet/src/Custom/Batch/BatchClient.cs | 73 ------------------- .../FineTuning/FineTuningClient.Protocol.cs | 56 ++++++++++++++ .../src/Custom/FineTuning/FineTuningClient.cs | 56 -------------- .../VectorStoreClient.Protocol.cs | 53 ++++++++++++++ .../Custom/VectorStores/VectorStoreClient.cs | 53 -------------- 12 files changed, 279 insertions(+), 281 deletions(-) diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/Batch/AzureBatchClient.Protocol.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/Batch/AzureBatchClient.Protocol.cs index 32bd8d37e..c32eddd3b 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/Batch/AzureBatchClient.Protocol.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/Batch/AzureBatchClient.Protocol.cs @@ -67,4 +67,39 @@ internal override ClientResult GetBatch(string batchId, RequestOptions options) using PipelineMessage message = CreateRetrieveBatchRequest(batchId, options); return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } + + internal override PipelineMessage CreateCreateBatchRequest(BinaryContent content, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) + .WithMethod("POST") + .WithPath("batches") + .WithContent(content, "application/json") + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateGetBatchesRequest(string after, int? limit, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) + .WithMethod("GET") + .WithPath("batches") + .WithOptionalQueryParameter("after", after) + .WithOptionalQueryParameter("limit", limit) + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) + .WithMethod("GET") + .WithPath("batches", batchId) + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) + .WithMethod("POST") + .WithPath("batches", batchId, "cancel") + .WithAccept("application/json") + .WithOptions(options) + .Build(); } diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/Batch/AzureBatchClient.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/Batch/AzureBatchClient.cs index 048552b6e..b1528365a 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/Batch/AzureBatchClient.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/Batch/AzureBatchClient.cs @@ -38,39 +38,4 @@ internal override CreateBatchOperation CreateCreateBatchOperation(string batchId { return new AzureCreateBatchOperation(Pipeline, _endpoint, batchId, status, response, _deploymentName, _apiVersion); } - - internal override PipelineMessage CreateCreateBatchRequest(BinaryContent content, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) - .WithMethod("POST") - .WithPath("batches") - .WithContent(content, "application/json") - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - internal override PipelineMessage CreateGetBatchesRequest(string after, int? limit, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) - .WithMethod("GET") - .WithPath("batches") - .WithOptionalQueryParameter("after", after) - .WithOptionalQueryParameter("limit", limit) - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - internal override PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) - .WithMethod("GET") - .WithPath("batches", batchId) - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - internal override PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion, _deploymentName) - .WithMethod("POST") - .WithPath("batches", batchId, "cancel") - .WithAccept("application/json") - .WithOptions(options) - .Build(); } diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs index 98353c64e..b81a8e6c2 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs @@ -26,4 +26,31 @@ public override async Task CreateJobAsync( AzureCreateJobOperation operation = new(Pipeline, _endpoint, jobId, status, response, _apiVersion); return await operation.WaitUntilAsync(waitUntilCompleted, options).ConfigureAwait(false); } + + internal override PipelineMessage CreateCreateFineTuningJobRequest(BinaryContent content, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) + .WithMethod("POST") + .WithPath("fine_tuning", "jobs") + .WithContent(content, "application/json") + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateGetPaginatedFineTuningJobsRequest(string after, int? limit, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) + .WithMethod("GET") + .WithPath("fine_tuning", "jobs") + .WithOptionalQueryParameter("after", after) + .WithOptionalQueryParameter("limit", limit) + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateRetrieveFineTuningJobRequest(string fineTuningJobId, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) + .WithMethod("GET") + .WithPath("fine_tuning", "jobs", fineTuningJobId) + .WithAccept("application/json") + .WithOptions(options) + .Build(); } diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.cs index 66e2e3392..7de9948c3 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.cs @@ -34,32 +34,5 @@ protected AzureFineTuningClient() internal override CreateJobOperation CreateCreateJobOperation(string jobId, string status, PipelineResponse response) { return new AzureCreateJobOperation(Pipeline, _endpoint, jobId, status, response, _apiVersion); - } - - internal override PipelineMessage CreateCreateFineTuningJobRequest(BinaryContent content, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("POST") - .WithPath("fine_tuning", "jobs") - .WithContent(content, "application/json") - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - internal override PipelineMessage CreateGetPaginatedFineTuningJobsRequest(string after, int? limit, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("GET") - .WithPath("fine_tuning", "jobs") - .WithOptionalQueryParameter("after", after) - .WithOptionalQueryParameter("limit", limit) - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - internal override PipelineMessage CreateRetrieveFineTuningJobRequest(string fineTuningJobId, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("GET") - .WithPath("fine_tuning", "jobs", fineTuningJobId) - .WithAccept("application/json") - .WithOptions(options) - .Build(); + } } diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/VectorStores/AzureVectorStoreClient.Protocol.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/VectorStores/AzureVectorStoreClient.Protocol.cs index b41cbd82a..acf760c1c 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/VectorStores/AzureVectorStoreClient.Protocol.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/VectorStores/AzureVectorStoreClient.Protocol.cs @@ -205,4 +205,38 @@ public override CreateBatchFileJobOperation CreateBatchFileJob( .WithAccept("application/json") .WithOptions(options) .Build(); + + internal override PipelineMessage CreateGetVectorStoreFileRequest(string vectorStoreId, string fileId, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) + .WithMethod("GET") + .WithPath("vector_stores", vectorStoreId, "files", fileId) + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateCreateVectorStoreRequest(BinaryContent content, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) + .WithMethod("POST") + .WithPath("vector_stores") + .WithContent(content, "application/json") + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateCreateVectorStoreFileBatchRequest(string vectorStoreId, BinaryContent content, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) + .WithMethod("POST") + .WithPath("vector_stores", vectorStoreId, "file_batches") + .WithContent(content, "application/json") + .WithAccept("application/json") + .WithOptions(options) + .Build(); + + internal override PipelineMessage CreateGetVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestOptions options) + => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) + .WithMethod("GET") + .WithPath("vector_stores", vectorStoreId, "file_batches", batchId) + .WithAccept("application/json") + .WithOptions(options) + .Build(); } diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/VectorStores/AzureVectorStoreClient.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/VectorStores/AzureVectorStoreClient.cs index 06da12928..cf4ea4eea 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/VectorStores/AzureVectorStoreClient.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/VectorStores/AzureVectorStoreClient.cs @@ -47,40 +47,4 @@ internal override CreateBatchFileJobOperation CreateBatchFileJobOperation(Client { return new AzureCreateBatchFileJobOperation(Pipeline, _endpoint, result, _apiVersion); } - - internal override PipelineMessage CreateGetVectorStoreFileRequest(string vectorStoreId, string fileId, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("GET") - .WithPath("vector_stores", vectorStoreId, "files", fileId) - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - internal override PipelineMessage CreateCreateVectorStoreRequest(BinaryContent content, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("POST") - .WithPath("vector_stores") - .WithContent(content, "application/json") - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - internal override PipelineMessage CreateCreateVectorStoreFileBatchRequest(string vectorStoreId, BinaryContent content, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("POST") - .WithPath("vector_stores", vectorStoreId, "file_batches") - .WithContent(content, "application/json") - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - internal override PipelineMessage CreateGetVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestOptions options) - => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) - .WithMethod("GET") - .WithPath("vector_stores", vectorStoreId, "file_batches", batchId) - .WithAccept("application/json") - .WithOptions(options) - .Build(); - - } diff --git a/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs b/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs index fa5894203..7e53129b8 100644 --- a/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs +++ b/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs @@ -129,4 +129,77 @@ internal virtual ClientResult GetBatch(string batchId, RequestOptions options) using PipelineMessage message = CreateRetrieveBatchRequest(batchId, options); return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); } + + internal virtual PipelineMessage CreateCreateBatchRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/batches", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateGetBatchesRequest(string after, int? limit, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/batches", false); + if (after != null) + { + uri.AppendQuery("after", after, true); + } + if (limit != null) + { + uri.AppendQuery("limit", limit.Value, true); + } + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/batches/", false); + uri.AppendPath(batchId, true); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/batches/", false); + uri.AppendPath(batchId, true); + uri.AppendPath("/cancel", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } } diff --git a/.dotnet/src/Custom/Batch/BatchClient.cs b/.dotnet/src/Custom/Batch/BatchClient.cs index e6add4633..c27ffd42a 100644 --- a/.dotnet/src/Custom/Batch/BatchClient.cs +++ b/.dotnet/src/Custom/Batch/BatchClient.cs @@ -66,77 +66,4 @@ internal virtual CreateBatchOperation CreateCreateBatchOperation(string batchId, { return new CreateBatchOperation(_pipeline, _endpoint, batchId, status, response); } - - internal virtual PipelineMessage CreateCreateBatchRequest(BinaryContent content, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "POST"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/batches", false); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - request.Headers.Set("Content-Type", "application/json"); - request.Content = content; - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateGetBatchesRequest(string after, int? limit, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/batches", false); - if (after != null) - { - uri.AppendQuery("after", after, true); - } - if (limit != null) - { - uri.AppendQuery("limit", limit.Value, true); - } - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateRetrieveBatchRequest(string batchId, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/batches/", false); - uri.AppendPath(batchId, true); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateCancelBatchRequest(string batchId, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "POST"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/batches/", false); - uri.AppendPath(batchId, true); - uri.AppendPath("/cancel", false); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } } diff --git a/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs b/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs index c61323716..c4d99794c 100644 --- a/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs +++ b/.dotnet/src/Custom/FineTuning/FineTuningClient.Protocol.cs @@ -176,4 +176,60 @@ internal virtual ClientResult GetJob(string fineTuningJobId, RequestOptions opti using PipelineMessage message = CreateRetrieveFineTuningJobRequest(fineTuningJobId, options); return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); } + + internal virtual PipelineMessage CreateCreateFineTuningJobRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/fine_tuning/jobs", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateGetPaginatedFineTuningJobsRequest(string after, int? limit, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/fine_tuning/jobs", false); + if (after != null) + { + uri.AppendQuery("after", after, true); + } + if (limit != null) + { + uri.AppendQuery("limit", limit.Value, true); + } + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateRetrieveFineTuningJobRequest(string fineTuningJobId, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/fine_tuning/jobs/", false); + uri.AppendPath(fineTuningJobId, true); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } } diff --git a/.dotnet/src/Custom/FineTuning/FineTuningClient.cs b/.dotnet/src/Custom/FineTuning/FineTuningClient.cs index 55fe1f53f..72e81cd5e 100644 --- a/.dotnet/src/Custom/FineTuning/FineTuningClient.cs +++ b/.dotnet/src/Custom/FineTuning/FineTuningClient.cs @@ -75,60 +75,4 @@ internal virtual CreateJobOperation CreateCreateJobOperation(string jobId, strin { return new CreateJobOperation(_pipeline, _endpoint, jobId, status, response); } - - internal virtual PipelineMessage CreateCreateFineTuningJobRequest(BinaryContent content, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "POST"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/fine_tuning/jobs", false); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - request.Headers.Set("Content-Type", "application/json"); - request.Content = content; - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateGetPaginatedFineTuningJobsRequest(string after, int? limit, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/fine_tuning/jobs", false); - if (after != null) - { - uri.AppendQuery("after", after, true); - } - if (limit != null) - { - uri.AppendQuery("limit", limit.Value, true); - } - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateRetrieveFineTuningJobRequest(string fineTuningJobId, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/fine_tuning/jobs/", false); - uri.AppendPath(fineTuningJobId, true); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } } diff --git a/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs b/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs index 133f764de..e8ec419dc 100644 --- a/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs +++ b/.dotnet/src/Custom/VectorStores/VectorStoreClient.Protocol.cs @@ -560,4 +560,57 @@ internal virtual ClientResult GetBatchFileJob(string vectorStoreId, string batch using PipelineMessage message = CreateGetVectorStoreFileBatchRequest(vectorStoreId, batchId, options); return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); } + + internal virtual PipelineMessage CreateGetVectorStoreFileRequest(string vectorStoreId, string fileId, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + uri.AppendPath("/files/", false); + uri.AppendPath(fileId, true); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateCreateVectorStoreRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + message.Apply(options); + return message; + } + + internal virtual PipelineMessage CreateGetVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + uri.AppendPath("/file_batches/", false); + uri.AppendPath(batchId, true); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } } diff --git a/.dotnet/src/Custom/VectorStores/VectorStoreClient.cs b/.dotnet/src/Custom/VectorStores/VectorStoreClient.cs index 6678c7b1a..43f6997c6 100644 --- a/.dotnet/src/Custom/VectorStores/VectorStoreClient.cs +++ b/.dotnet/src/Custom/VectorStores/VectorStoreClient.cs @@ -579,58 +579,5 @@ internal virtual PipelineMessage CreateCreateVectorStoreFileBatchRequest(string request.Content = content; message.Apply(options); return message; - } - - internal virtual PipelineMessage CreateGetVectorStoreFileRequest(string vectorStoreId, string fileId, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/vector_stores/", false); - uri.AppendPath(vectorStoreId, true); - uri.AppendPath("/files/", false); - uri.AppendPath(fileId, true); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateCreateVectorStoreRequest(BinaryContent content, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "POST"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/vector_stores", false); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - request.Headers.Set("Content-Type", "application/json"); - request.Content = content; - message.Apply(options); - return message; - } - - internal virtual PipelineMessage CreateGetVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestOptions options) - { - var message = _pipeline.CreateMessage(); - message.ResponseClassifier = PipelineMessageClassifier200; - var request = message.Request; - request.Method = "GET"; - var uri = new ClientUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/vector_stores/", false); - uri.AppendPath(vectorStoreId, true); - uri.AppendPath("/file_batches/", false); - uri.AppendPath(batchId, true); - request.Uri = uri.ToUri(); - request.Headers.Set("Accept", "application/json"); - message.Apply(options); - return message; } } From e3a4a40b63191d772b0d8c9ea22c3b78463cf9c4 Mon Sep 17 00:00:00 2001 From: chschrae Date: Tue, 17 Sep 2024 12:32:45 -0700 Subject: [PATCH 11/18] fixing openAI file client in tests --- .dotnet/tests/Batch/BatchTests.cs | 2 +- .dotnet/tests/FineTuning/FineTuningTests.cs | 2 +- .dotnet/tests/Utility/TestHelpers.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.dotnet/tests/Batch/BatchTests.cs b/.dotnet/tests/Batch/BatchTests.cs index 8bfe2a72c..26ab43fec 100644 --- a/.dotnet/tests/Batch/BatchTests.cs +++ b/.dotnet/tests/Batch/BatchTests.cs @@ -177,7 +177,7 @@ public async Task CanRehydrateBatchOperation() streamWriter.Flush(); testFileStream.Position = 0; - FileClient fileClient = new(); + FileClient fileClient = GetTestClient(TestScenario.Files); OpenAIFileInfo inputFile = await fileClient.UploadFileAsync(testFileStream, "test-batch-file", FileUploadPurpose.Batch); Assert.That(inputFile.Id, Is.Not.Null.And.Not.Empty); diff --git a/.dotnet/tests/FineTuning/FineTuningTests.cs b/.dotnet/tests/FineTuning/FineTuningTests.cs index 0da09ac30..dd1482fcf 100644 --- a/.dotnet/tests/FineTuning/FineTuningTests.cs +++ b/.dotnet/tests/FineTuning/FineTuningTests.cs @@ -45,7 +45,7 @@ protected void Cleanup() return; } - FileClient fileClient = new(); + FileClient fileClient = GetTestClient(TestScenario.Files); RequestOptions requestOptions = new() { ErrorOptions = ClientErrorBehaviors.NoThrow, diff --git a/.dotnet/tests/Utility/TestHelpers.cs b/.dotnet/tests/Utility/TestHelpers.cs index 134540304..8941aa5a2 100644 --- a/.dotnet/tests/Utility/TestHelpers.cs +++ b/.dotnet/tests/Utility/TestHelpers.cs @@ -62,7 +62,7 @@ public static T GetTestClient(TestScenario scenario, string overrideModel = n TestScenario.Images => new ImageClient(overrideModel ?? "dall-e-3", credential, options), TestScenario.Models => new ModelClient(credential, options), TestScenario.Moderations => new ModerationClient(overrideModel ?? "text-moderation-stable", credential, options), - TestScenario.FineTuning => new FineTuningClient(options), + TestScenario.FineTuning => new FineTuningClient(credential, options), #pragma warning disable OPENAI001 TestScenario.VectorStores => new VectorStoreClient(credential, options), #pragma warning restore OPENAI001 From 38e6f76d1583ca54eae94ba34042e3956154e1c3 Mon Sep 17 00:00:00 2001 From: chschrae Date: Tue, 17 Sep 2024 14:37:44 -0700 Subject: [PATCH 12/18] added missing paginatio to fine tuning --- .../FineTuning/AzureFineTuningClient.Protocol.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs index b81a8e6c2..666321ba4 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureFineTuningClient.Protocol.cs @@ -27,6 +27,18 @@ public override async Task CreateJobAsync( return await operation.WaitUntilAsync(waitUntilCompleted, options).ConfigureAwait(false); } + public override IAsyncEnumerable GetJobsAsync(string after, int? limit, RequestOptions options) + { + AzureFineTuningJobsPageEnumerator enumerator = new AzureFineTuningJobsPageEnumerator(Pipeline, _endpoint, after, limit, _apiVersion, options); + return PageCollectionHelpers.CreateAsync(enumerator); + } + + public override IEnumerable GetJobs(string after, int? limit, RequestOptions options) + { + AzureFineTuningJobsPageEnumerator enumerator = new AzureFineTuningJobsPageEnumerator(Pipeline, _endpoint, after, limit, _apiVersion, options); + return PageCollectionHelpers.Create(enumerator); + } + internal override PipelineMessage CreateCreateFineTuningJobRequest(BinaryContent content, RequestOptions options) => new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion) .WithMethod("POST") From 108ab925511f6fed8050e349d85c830785d65205 Mon Sep 17 00:00:00 2001 From: Christopher Schraer <32145632+chschrae@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:43:44 -0700 Subject: [PATCH 13/18] Update .dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs Co-authored-by: Anne Thompson <21269347+annelo-msft@users.noreply.github.com> --- .../sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs index 2b652bc63..d5c43640d 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs @@ -209,7 +209,7 @@ public async Task CreateAndDeleteFineTuning() TrainingFile = uploadedFile.Id }.ToBinaryContent(); - CreateJobOperation operation = await client.CreateJobAsync(requestContent, false); + CreateJobOperation operation = await client.CreateJobAsync(requestContent, waitForCompletion: false); FineTuningJob job = ValidateAndParse(await operation.GetJobAsync(null)); Assert.That(job.ID, Is.Not.Null.Or.Empty); Assert.That(job.Error, Is.Null); From d8d82ef38375da3f097f66d83c673ae487bd9a04 Mon Sep 17 00:00:00 2001 From: Christopher Schraer <32145632+chschrae@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:44:28 -0700 Subject: [PATCH 14/18] Update .dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs Co-authored-by: Anne Thompson <21269347+annelo-msft@users.noreply.github.com> --- .../sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs index 05a518451..9ae70b438 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs @@ -37,7 +37,7 @@ public async Task CanCreateGetAndDeleteVectorStores() { VectorStoreClient client = GetTestClient(); - CreateVectorStoreOperation createVectorStoreOperation = await client.CreateVectorStoreAsync(false); + CreateVectorStoreOperation createVectorStoreOperation = await client.CreateVectorStoreAsync(waitUntilCompleted: false); Validate(createVectorStoreOperation); bool deleted = await client.DeleteVectorStoreAsync(createVectorStoreOperation.GetVectorStore()); Assert.That(deleted, Is.True); From 7373eb809705d88755372454dc0fc4c6672ee9f7 Mon Sep 17 00:00:00 2001 From: chschrae Date: Tue, 17 Sep 2024 17:03:59 -0700 Subject: [PATCH 15/18] PR nits and responses --- .../openai/Azure.AI.OpenAI/tests/FineTuningTests.cs | 12 ++++++------ .../openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs | 8 ++++---- .dotnet/src/Custom/Batch/BatchClient.Protocol.cs | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs index 2b652bc63..81c256992 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs @@ -22,7 +22,7 @@ namespace Azure.AI.OpenAI.Tests; public class FineTuningTests : AoaiTestBase { - public FineTuningTests(bool isAsync) : base(isAsync, RecordedTestMode.Live) + public FineTuningTests(bool isAsync) : base(isAsync) { } [Test] @@ -145,7 +145,7 @@ public async Task CreateAndCancelFineTuning() TrainingFile = uploadedFile.Id }.ToBinaryContent(); - //TODO handle synchronous versions of operations + // TODO handle synchronous versions of operations CreateJobOperation operation = await client.CreateJobAsync(requestContent, new()); var jobFromResult = await operation.GetJobAsync(null); FineTuningJob job = ValidateAndParse(jobFromResult); @@ -156,9 +156,9 @@ public async Task CreateAndCancelFineTuning() Assert.True(deleted, "Failed to delete fine tuning job: {0}", job.ID); }); - //Wait for some events to become available + // Wait for some events to become available ClientResult result; - ListResponse < FineTuningJobEvent > events; + ListResponse events; int maxLoops = 10; do { @@ -181,7 +181,7 @@ public async Task CreateAndCancelFineTuning() } while (maxLoops-- > 0); // Cancel the fine tuning job - result = await operation.CancelAsync(null); + result = await operation.CancelAsync(options: null); job = ValidateAndParse(result); // Make sure the job status shows as cancelled @@ -210,7 +210,7 @@ public async Task CreateAndDeleteFineTuning() }.ToBinaryContent(); CreateJobOperation operation = await client.CreateJobAsync(requestContent, false); - FineTuningJob job = ValidateAndParse(await operation.GetJobAsync(null)); + FineTuningJob job = ValidateAndParse(ClientResult.FromResponse(operation.GetRawResponse())); Assert.That(job.ID, Is.Not.Null.Or.Empty); Assert.That(job.Error, Is.Null); Assert.That(job.Status, !(Is.Null.Or.EqualTo("failed").Or.EqualTo("cancelled"))); diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs index 05a518451..040de518b 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs @@ -71,7 +71,7 @@ public async Task CanCreateGetAndDeleteVectorStores() Assert.That(vectorStore.Status, Is.EqualTo(VectorStoreStatus.InProgress)); Assert.That(vectorStore.Metadata?.TryGetValue("test-key", out string metadataValue) == true && metadataValue == "test-value"); }); - vectorStore = createVectorStoreOperation.GetVectorStore(); + vectorStore = createVectorStoreOperation.Value; Assert.Multiple(() => { Assert.That(vectorStore.Name, Is.EqualTo("test vector store")); @@ -147,7 +147,7 @@ public async Task CanAssociateFiles() { VectorStoreClient client = GetTestClient(); CreateVectorStoreOperation createVectorStoreOperation = await client.CreateVectorStoreAsync(false); - VectorStore vectorStore = createVectorStoreOperation.GetVectorStore(); + VectorStore vectorStore = createVectorStoreOperation.Value; Validate(vectorStore); IReadOnlyList files = await GetNewTestFilesAsync(client.GetConfigOrThrow(), 3); @@ -155,7 +155,7 @@ public async Task CanAssociateFiles() foreach (OpenAIFileInfo file in files) { AddFileToVectorStoreOperation addFileToVectorStoreOperation = await client.AddFileToVectorStoreAsync(vectorStore, file, false); - VectorStoreFileAssociation association = addFileToVectorStoreOperation.GetFileAssociation(); + VectorStoreFileAssociation association = addFileToVectorStoreOperation.Value; Validate(association); Assert.Multiple(() => { @@ -208,7 +208,7 @@ public async Task CanUseBatchIngestion() batchJob = createBatchFileJobOperation.GetFileBatch(); Assert.That(batchJob.Status, Is.EqualTo(VectorStoreBatchFileJobStatus.Completed)); - AsyncPageCollection response = client.GetFileAssociationsAsync(vectorStore); + AsyncPageCollection response = createBatchFileJobOperation.GetFilesInBatchAsync(); await foreach (VectorStoreFileAssociation association in response.GetAllValuesAsync()) { Assert.Multiple(() => diff --git a/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs b/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs index 7e53129b8..89b3abc0f 100644 --- a/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs +++ b/.dotnet/src/Custom/Batch/BatchClient.Protocol.cs @@ -22,7 +22,7 @@ public partial class BatchClient /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// Service returned a non-success status code. - /// A that can be used to wait for + /// A that can be used to wait for /// the operation to complete, or cancel the operation. public virtual async Task CreateBatchAsync(BinaryContent content, bool waitUntilCompleted, RequestOptions options = null) { @@ -51,7 +51,7 @@ public virtual async Task CreateBatchAsync(BinaryContent c /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// Service returned a non-success status code. - /// A that can be used to wait for + /// A that can be used to wait for /// the operation to complete, or cancel the operation. public virtual CreateBatchOperation CreateBatch(BinaryContent content, bool waitUntilCompleted, RequestOptions options = null) { From deae729e4e5470ab2f09ae5e5a20eee31bf7a32a Mon Sep 17 00:00:00 2001 From: chschrae Date: Tue, 17 Sep 2024 17:10:36 -0700 Subject: [PATCH 16/18] parameter name mismatch fixed --- .../sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs index 0386520e6..ba6a741a6 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/FineTuningTests.cs @@ -209,7 +209,7 @@ public async Task CreateAndDeleteFineTuning() TrainingFile = uploadedFile.Id }.ToBinaryContent(); - CreateJobOperation operation = await client.CreateJobAsync(requestContent, waitForCompletion: false); + CreateJobOperation operation = await client.CreateJobAsync(requestContent, waitUntilCompleted: false); FineTuningJob job = ValidateAndParse(ClientResult.FromResponse(operation.GetRawResponse())); Assert.That(job.ID, Is.Not.Null.Or.Empty); Assert.That(job.Error, Is.Null); From 4ed3408f494f3cfacba8f9603c4df8da6ee4198d Mon Sep 17 00:00:00 2001 From: chschrae Date: Thu, 19 Sep 2024 11:43:02 -0700 Subject: [PATCH 17/18] pr somments --- .../src/Custom/Batch/AzureCreateBatchOperation.Protocol.cs | 2 +- .../Custom/FineTuning/AzureCreateJobOperation.Protocol.cs | 6 ++++-- .../Custom/VectorStores/AzureCreateVectorStoreOperation.cs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/Batch/AzureCreateBatchOperation.Protocol.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/Batch/AzureCreateBatchOperation.Protocol.cs index 8dff3182b..49e12ee0e 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/Batch/AzureCreateBatchOperation.Protocol.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/Batch/AzureCreateBatchOperation.Protocol.cs @@ -9,7 +9,7 @@ namespace Azure.AI.OpenAI.Batch; /// A long-running operation for executing a batch from an uploaded file of /// requests. /// -public partial class AzureCreateBatchOperation : CreateBatchOperation +internal partial class AzureCreateBatchOperation : CreateBatchOperation { private readonly ClientPipeline _pipeline; private readonly Uri _endpoint; diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs index 02af08875..6a3ae030b 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/FineTuning/AzureCreateJobOperation.Protocol.cs @@ -9,9 +9,10 @@ namespace Azure.AI.OpenAI.FineTuning; /// /// A long-running operation for creating a new model from a given dataset. /// +[Experimental("OPENAI001")] public class AzureCreateJobOperation : CreateJobOperation { - private readonly PipelineMessageClassifier DeleteJobClassifier = PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + private readonly PipelineMessageClassifier _deleteJobClassifier; private readonly ClientPipeline _pipeline; private readonly Uri _endpoint; private readonly string _jobId; @@ -31,6 +32,7 @@ internal AzureCreateJobOperation( _endpoint = endpoint; _jobId = jobId; _apiVersion = apiVersion; + _deleteJobClassifier = PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); } [Experimental("AOAI001")] @@ -53,7 +55,7 @@ private PipelineMessage CreateDeleteJobRequestMessage(string fineTuningJobId, Re .WithMethod("DELETE") .WithPath("fine_tuning", "jobs", fineTuningJobId) .WithAccept("application/json") - .WithClassifier(DeleteJobClassifier) + .WithClassifier(_deleteJobClassifier) .WithOptions(options) .Build(); diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/VectorStores/AzureCreateVectorStoreOperation.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/VectorStores/AzureCreateVectorStoreOperation.cs index a0707f371..cef4f3aa6 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/VectorStores/AzureCreateVectorStoreOperation.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/src/Custom/VectorStores/AzureCreateVectorStoreOperation.cs @@ -5,7 +5,7 @@ namespace Azure.AI.OpenAI.VectorStores; [Experimental("OPENAI001")] -public class AzureCreateVectorStoreOperation : CreateVectorStoreOperation +internal class AzureCreateVectorStoreOperation : CreateVectorStoreOperation { private readonly ClientPipeline _pipeline; private readonly Uri _endpoint; From 317601adc1ae4f2b9f2623c4ccdd8b18f17bd41f Mon Sep 17 00:00:00 2001 From: chschrae Date: Thu, 19 Sep 2024 11:59:50 -0700 Subject: [PATCH 18/18] updating vector store tests to use Value --- .../openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs index 95a9d55f1..f726d2710 100644 --- a/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs +++ b/.dotnet.azure/sdk/openai/Azure.AI.OpenAI/tests/VectorStoreTests.cs @@ -38,8 +38,8 @@ public async Task CanCreateGetAndDeleteVectorStores() VectorStoreClient client = GetTestClient(); CreateVectorStoreOperation createVectorStoreOperation = await client.CreateVectorStoreAsync(waitUntilCompleted: false); - Validate(createVectorStoreOperation); - bool deleted = await client.DeleteVectorStoreAsync(createVectorStoreOperation.GetVectorStore()); + Validate(createVectorStoreOperation.Value); + bool deleted = await client.DeleteVectorStoreAsync(createVectorStoreOperation.Value); Assert.That(deleted, Is.True); IReadOnlyList testFiles = await GetNewTestFilesAsync(client.GetConfigOrThrow(), 5); @@ -58,8 +58,8 @@ public async Task CanCreateGetAndDeleteVectorStores() ["test-key"] = "test-value", }, }); - Validate(createVectorStoreOperation); - VectorStore vectorStore = createVectorStoreOperation.GetVectorStore(); + Validate(createVectorStoreOperation.Value); + VectorStore vectorStore = createVectorStoreOperation.Value; Assert.Multiple(() => { Assert.That(vectorStore.Name, Is.EqualTo("test vector store")); @@ -91,7 +91,7 @@ public async Task CanCreateGetAndDeleteVectorStores() FileIds = testFiles.Select(file => file.Id).ToList() }); - vectorStore = createVectorStoreOperation.GetVectorStore(); + vectorStore = createVectorStoreOperation.Value; Validate(vectorStore); Assert.Multiple(() => {