Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience layer to FineTuning with tests #185

Open
wants to merge 131 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
4106c27
Add convenience layer to FineTuning with tests
mikhail Jul 30, 2024
07de547
Regenerate API summary
mikhail Aug 2, 2024
1229eae
initial custom types for request-side ft hyperparameters
trrwilson Aug 5, 2024
c1cf612
added test for invalid model
Aug 7, 2024
b828abc
separated model name test
Aug 7, 2024
2fd8383
Grab batch size and LRM from response
mikhail Aug 7, 2024
f1903b7
Fix some tests and fix merge conflicts
mikhail Aug 7, 2024
5d59221
set NEpochs and BatchSize to be ints while LRM remains float
mikhail Aug 7, 2024
b6242db
Merge branch 'main' into user/travisw/custom-ft-types-for-hyperparame…
trrwilson Aug 7, 2024
bb6437e
update: address customization for response hyperparameters
trrwilson Aug 7, 2024
5ffa2d4
Merge remote-tracking branch 'jose/user/travisw/custom-ft-types-for-h…
mikhail Aug 7, 2024
46d933b
Change Hyperparameters yaml definition to include batch and LRM
mikhail Aug 8, 2024
ebb4c07
Add WaitUntilCompleted convenience method to FineTuningClient
mikhail Aug 9, 2024
54c43c1
Add PlaygroundURL convenience method to FineTuningJob
mikhail Aug 9, 2024
0f3b3d4
Add parameters for Suffix and Seed
mikhail Aug 12, 2024
86e3c7c
Add WandB integration test for FineTuningClient
mikhail Aug 12, 2024
070e293
Allow seed value to be null
mikhail Aug 13, 2024
2cdaf14
added validation file id to CreateAndCancelJob and CreateAndCancelJob…
Aug 13, 2024
72b2fd9
added CreateAndCancelJobAsync tests
Aug 13, 2024
c9d617e
Merge branch 'main' of https://github.com/mikhail/openai-in-typespec …
Aug 13, 2024
d040143
Merged from main
Aug 13, 2024
0c2987a
handling merge conflicts
Aug 13, 2024
6b87c24
Reshuffle the tests to be cleaner and more consistent
mikhail Aug 13, 2024
b913d7c
Rename NEpochs to CycleCount and EstimatedFinish+At
mikhail Aug 14, 2024
527bdf8
Rename ValidationFile+Id
mikhail Aug 14, 2024
e2fe7c3
Rename TrainingFile+Id
mikhail Aug 14, 2024
1ce4d2a
Rename ResultFiles -> ResultFileIds
mikhail Aug 14, 2024
2f0650c
Update OpenAI.netstandard
mikhail Aug 14, 2024
1725b45
Convert convenience layers to *Options convention
mikhail Aug 15, 2024
e322f9e
Allow easier comparing of Hyperparams to primitive types
mikhail Aug 16, 2024
aea5371
Add 'virtual' to method definition in FT Client
mikhail Aug 19, 2024
079c4a4
Add .ConfigureAwait(false) to async calls inside FT Client
mikhail Aug 19, 2024
bbf0d32
Improve naming convention
mikhail Aug 19, 2024
c2f28c0
Add helper function for Integrations
mikhail Aug 19, 2024
ab8b496
add spec update for discriminated integration base, user_provided_suffix
trrwilson Aug 21, 2024
88a5cf4
FineTuningJobObject
trrwilson Aug 21, 2024
2ff352c
Fix Inner type mapping of wandb (#2)
trrwilson Aug 22, 2024
436064c
Merge remote-tracking branch 'jose/main'
mikhail Aug 22, 2024
ebe3744
Fix issues not caught during merging
mikhail Aug 22, 2024
8249a0e
Hyperparameters changes to params instead of getters
mikhail Aug 22, 2024
d3c7a34
Fix file->sampleFile renaming blunder
mikhail Aug 22, 2024
2bfc829
Remove ConvertTo-Internal
mikhail Aug 23, 2024
43dbae2
Rename model to baseModel
mikhail Aug 23, 2024
96a7ab0
Convert GetPlaygroundURL to PlaygroundUri
mikhail Aug 23, 2024
cecb0de
Rename TrainedTokens to BillableTrainedTOkens
mikhail Aug 23, 2024
c13bec0
Rename error param to InvalidParameter
mikhail Aug 23, 2024
9e0fc9d
Convert InProgress() to parameter and add a test
mikhail Aug 23, 2024
b62a971
Convert FineTuningJobEvent to public
mikhail Aug 26, 2024
40e3c66
building test push
trrwilson Aug 26, 2024
da90865
Fix bugs
mikhail Aug 26, 2024
a2c606c
Merge remote-tracking branch 'jose/main'
mikhail Aug 26, 2024
c42e16d
Fix bugs
mikhail Aug 27, 2024
4b9cee3
Merge remote-tracking branch 'jose/main'
mikhail Aug 27, 2024
855e4ea
Add FineTuning Events layer with pagination
mikhail Aug 28, 2024
d8f0396
Merge remote-tracking branch 'jose/main'
mikhail Aug 28, 2024
c9c20cf
Merge remote-tracking branch 'jose/main'
mikhail Aug 28, 2024
b0dbf7d
Apply dotnet format
mikhail Aug 28, 2024
5867d63
Use *Options pattern for events
mikhail Sep 3, 2024
f0abba3
Merge remote-tracking branch 'jose/main'
mikhail Sep 5, 2024
67633e3
Address review feedback
mikhail Sep 5, 2024
1fe77db
Rename FineTuningJobError to JobError
mikhail Sep 5, 2024
c406343
Remove constructor from HyperparameterOptions
mikhail Sep 5, 2024
7994617
Add GetJobs()
mikhail Sep 10, 2024
6239a6c
Merge remote-tracking branch 'jose/main'
mikhail Sep 10, 2024
5e8b77f
Merge remote-tracking branch 'jose/main'
mikhail Sep 13, 2024
551768a
Fix tests after merge
mikhail Sep 13, 2024
90b49d8
Add a test for GetJobsWithAfter
mikhail Sep 23, 2024
eda5c67
Merge remote-tracking branch 'jose/main'
mikhail Sep 23, 2024
a39c524
Add pagination for GetJobs
mikhail Sep 24, 2024
468f1b8
Remove limit in favor of .Take(). Dedup Sync/Async tests
mikhail Sep 24, 2024
89368f2
Format all code with dotnet format
mikhail Sep 24, 2024
4fdecdd
Convert after and pagesize to ListJobsOptions
mikhail Sep 24, 2024
2b014ab
Add FT Checkpoints code
mikhail Sep 25, 2024
6a1a109
Merge remote-tracking branch 'jose/main'
mikhail Sep 25, 2024
ce0b012
Fix tests after merge
mikhail Sep 25, 2024
4ece71e
Tidy up FineTuningClient.cs
mikhail Sep 25, 2024
34d0c63
Export API
mikhail Sep 25, 2024
c8d314f
Remove cast checking
mikhail Sep 25, 2024
49a418e
Add test for checkpotin metrics
mikhail Sep 25, 2024
5e9c924
Add assembly reference and regenerate API export
mikhail Sep 25, 2024
923c8e8
Merge remote-tracking branch 'jose/main'
mikhail Sep 26, 2024
c2e51e8
Fix tests after merge
mikhail Sep 27, 2024
2644e7e
Add .Value to FTJ Operation
mikhail Sep 30, 2024
4b0d928
Merge remote-tracking branch 'jose/main'
mikhail Sep 30, 2024
8170f45
Tidy up LRO for fine tuning
mikhail Oct 7, 2024
3349abe
Merge remote-tracking branch 'jose/main'
mikhail Oct 7, 2024
112ce79
LRO Convenience layer touch up for Fine Tuning
mikhail Oct 8, 2024
c0a234e
Remove debug lines
mikhail Oct 8, 2024
872d994
Call Protocol method from convenience layer when possible.
mikhail Oct 10, 2024
3f61acd
CRLF -> LF
mikhail Oct 10, 2024
b3d0ae9
PR comments. Internal/Private. Whitespace.
mikhail Oct 10, 2024
cf62b28
Set HasCompleted on result update. Fix GetJob casting
mikhail Oct 14, 2024
e23914a
Merge remote-tracking branch 'jose/main'
mikhail Oct 14, 2024
bd868bd
Merge remote-tracking branch 'jose/main'
mikhail Oct 15, 2024
08fd6fa
Merge remote-tracking branch 'jose/main'
mikhail Oct 23, 2024
002b13d
Make FineTuningOperation primary class and hide 'Job'
mikhail Nov 1, 2024
af46fd1
Merge remote-tracking branch 'jose/main'
mikhail Nov 1, 2024
b32e9c9
Rerun codegen
mikhail Nov 1, 2024
c5f2892
Improve naming around PipelineMessages
mikhail Nov 1, 2024
b481ab9
Improve method naming around FineTuning
mikhail Nov 4, 2024
6a2338c
Improve class naming around FineTuning
mikhail Nov 4, 2024
f355d77
Rename FineTuningJobId to JobId
mikhail Nov 5, 2024
9097b16
Rename all Operation to Job
mikhail Nov 19, 2024
60aea0d
Final touches renaming Operation to Job
mikhail Nov 22, 2024
d98008b
Minor renames in preliminary APIView review
mikhail Nov 22, 2024
963a200
Minor renames in preliminary APIView review, part 2
mikhail Nov 22, 2024
a2f908f
Merge remote-tracking branch 'jose/main'
mikhail Nov 22, 2024
dc4c97d
Fix Azure FT tests
mikhail Dec 17, 2024
7105580
Fix Azure FT file name typo
mikhail Dec 17, 2024
5d9df0a
Merge remote-tracking branch 'jose/main' compilation is failing
mikhail Dec 17, 2024
9b315fd
Fixing post merge issues
mikhail Jan 6, 2025
c22818b
Fixing post merge issues pt 2
mikhail Jan 7, 2025
e8c4f28
Partial port of spec update for "method" + hyperparameter contemporar…
trrwilson Jan 9, 2025
8383016
Debug CheckpointsFineTuning()
mikhail Jan 14, 2025
906bce8
Remove API Version from pipeline message builder
mikhail Jan 23, 2025
2ab02ca
Merge remote-tracking branch 'jose/main'
mikhail Jan 23, 2025
522a7c8
Fix up smoke tests
mikhail Jan 24, 2025
ad81d21
Mark deletion test as Live
mikhail Jan 24, 2025
3fcdca8
Use the new assets tag
mikhail Jan 25, 2025
c11016b
Use the new assets tag and comment out ConversationTests rate limits
mikhail Jan 25, 2025
62a9db7
Bump assets tag
mikhail Jan 25, 2025
e247dc2
Mark everything as experimental
mikhail Jan 27, 2025
330616b
Update OpenAI.netstandard
mikhail Jan 27, 2025
b1d77f5
Convert RequestModel to String
mikhail Feb 4, 2025
bebcdc6
Introduce MethodHyperparameters
mikhail Feb 24, 2025
48fe833
Merge remote-tracking branch 'jose/main'
mikhail Feb 25, 2025
31dabd9
Get to compile after merge
mikhail Feb 26, 2025
4072556
AOAI FineTuning missing version in api call
mikhail Feb 26, 2025
bef5bc6
Revert "Remove API Version from pipeline message builder"
mikhail Feb 26, 2025
c1cff5b
Broken: getting to azureFineTuningJob
mikhail Feb 27, 2025
4ce93a6
CreateCancelDelete test works
mikhail Mar 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
global using OpenAI.VectorStores;
#if !AZURE_OPENAI_GA
global using OpenAI.RealtimeConversation;
using Azure.AI.OpenAI.Assistants;
using Azure.AI.OpenAI.FineTuning;
using Azure.AI.OpenAI.RealtimeConversation;
using Azure.AI.OpenAI.VectorStores;
#endif

using System.ClientModel;
Expand All @@ -29,13 +33,6 @@
using Azure.AI.OpenAI.Images;
using Azure.Core;

#if !AZURE_OPENAI_GA
using Azure.AI.OpenAI.Assistants;
using Azure.AI.OpenAI.FineTuning;
using Azure.AI.OpenAI.RealtimeConversation;
using Azure.AI.OpenAI.VectorStores;
#endif

#pragma warning disable AZC0007

namespace Azure.AI.OpenAI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,67 @@
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;
using System.Linq;
using Azure.AI.OpenAI.Utility;

namespace Azure.AI.OpenAI.FineTuning;

internal partial class AzureFineTuningClient : FineTuningClient
{
public override async Task<FineTuningJobOperation> CreateFineTuningJobAsync(
public override async Task<FineTuningJob> FineTuneAsync(
BinaryContent content,
bool waitUntilCompleted,
RequestOptions options = null)
{
Argument.AssertNotNull(content, nameof(content));

using PipelineMessage message = CreateCreateFineTuningJobRequest(content, options);
using PipelineMessage message = PostJobPipelineMessage(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();

AzureFineTuningJobOperation operation = new(Pipeline, _endpoint, jobId, status, response, _apiVersion);
AzureFineTuningJob operation = new(Pipeline, _endpoint, response, _apiVersion);
return await operation.WaitUntilAsync(waitUntilCompleted, options).ConfigureAwait(false);
}

public override FineTuningJobOperation CreateFineTuningJob(
public override FineTuningJob FineTune(
BinaryContent content,
bool waitUntilCompleted,
RequestOptions options = null)
{
Argument.AssertNotNull(content, nameof(content));

using PipelineMessage message = CreateCreateFineTuningJobRequest(content, options);
using PipelineMessage message = PostJobPipelineMessage(content, options);
PipelineResponse response = Pipeline.ProcessMessage(message, options);

using JsonDocument doc = JsonDocument.Parse(response.Content);
string jobId = doc.RootElement.GetProperty("id"u8).GetString();
string status = doc.RootElement.GetProperty("status"u8).GetString();

AzureFineTuningJobOperation operation = new(Pipeline, _endpoint, jobId, status, response, _apiVersion);
AzureFineTuningJob operation = new(Pipeline, _endpoint, response, _apiVersion);
return operation.WaitUntil(waitUntilCompleted, options);
}

public override AsyncCollectionResult GetJobsAsync(string after, int? limit, RequestOptions options)
internal override AsyncCollectionResult GetJobsAsync(string afterJobId, int? pageSize, RequestOptions options)
{
return new AsyncFineTuningJobCollectionResult(this, Pipeline, options, limit, after);
return new AzureAsyncCollectionResult<FineTuningJob, FineTuningCollectionPageToken>(
Pipeline,
options,
continuation => GetJobsPipelineMessage(continuation?.After, pageSize, options),
page => FineTuningCollectionPageToken.FromResponse(page, pageSize),
page => GetJobsFromResponse(page.GetRawResponse()),
options?.CancellationToken ?? default
);
}

public override CollectionResult GetJobs(string after, int? limit, RequestOptions options)
private IEnumerable<FineTuningJob> GetJobsFromResponse(PipelineResponse response)
{
return new FineTuningJobCollectionResult(this, Pipeline, options, limit, after);
InternalListPaginatedFineTuningJobsResponse jobs = ModelReaderWriter.Read<InternalListPaginatedFineTuningJobsResponse>(response.Content)!;
return jobs.Data.Select(job => new AzureFineTuningJob(Pipeline, _endpoint, response, _apiVersion, job));
}

public override async Task<ClientResult> GetJobAsync(string fineTuningJobId, RequestOptions options)
{
using PipelineMessage message = CreateRetrieveFineTuningJobRequest(fineTuningJobId, options);
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
}

public override ClientResult GetJob(string fineTuningJobId, RequestOptions options)
{
Argument.AssertNotNullOrEmpty(fineTuningJobId, nameof(fineTuningJobId));

using PipelineMessage message = CreateRetrieveFineTuningJobRequest(fineTuningJobId, options);
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
}

internal override PipelineMessage CreateCreateFineTuningJobRequest(BinaryContent content, RequestOptions options)
internal override PipelineMessage PostJobPipelineMessage(BinaryContent content, RequestOptions options)
=> new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion)
.WithMethod("POST")
.WithPath("fine_tuning", "jobs")
Expand All @@ -80,7 +75,7 @@ internal override PipelineMessage CreateCreateFineTuningJobRequest(BinaryContent
.WithOptions(options)
.Build();

internal override PipelineMessage CreateGetPaginatedFineTuningJobsRequest(string after, int? limit, RequestOptions options)
internal override PipelineMessage GetJobsPipelineMessage(string after, int? limit, RequestOptions options)
=> new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion)
.WithMethod("GET")
.WithPath("fine_tuning", "jobs")
Expand All @@ -90,13 +85,13 @@ internal override PipelineMessage CreateGetPaginatedFineTuningJobsRequest(string
.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 static new PipelineMessage GetJobPipelineMessage(ClientPipeline clientPipeline, Uri endpoint, string fineTuningJobId, RequestOptions options)
// => new AzureOpenAIPipelineMessageBuilder(clientPipeline, endpoint, _apiVersion)
// .WithMethod("GET")
// .WithPath("fine_tuning", "jobs", fineTuningJobId)
// .WithAccept("application/json")
// .WithOptions(options)
// .Build();

private static bool TryGetLastId(ClientResult previous, out string lastId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

using System.ClientModel;
using System.ClientModel.Primitives;
using System.Diagnostics.CodeAnalysis;
using System.Net;

namespace Azure.AI.OpenAI.FineTuning;

Expand All @@ -14,12 +16,15 @@ namespace Azure.AI.OpenAI.FineTuning;
/// <remarks>
/// To retrieve an instance of this type, use the matching method on <see cref="AzureOpenAIClient"/>.
/// </remarks>
[Experimental("OPENAI001")]
internal partial class AzureFineTuningClient : FineTuningClient
{
private readonly Uri _endpoint;
private readonly string _apiVersion;

[Experimental("OPENAI001")]
internal AzureFineTuningClient(ClientPipeline pipeline, Uri endpoint, AzureOpenAIClientOptions options)
// : base(pipeline, new OpenAIClientOptions() { Endpoint = endpoint })
: base(pipeline, new OpenAIClientOptions() { Endpoint = endpoint })
{
Argument.AssertNotNull(pipeline, nameof(pipeline));
Expand All @@ -30,12 +35,45 @@ internal AzureFineTuningClient(ClientPipeline pipeline, Uri endpoint, AzureOpenA
_apiVersion = options.GetRawServiceApiValueForClient(this);
}

[Experimental("OPENAI001")]
protected AzureFineTuningClient()
{ }

internal override FineTuningJobOperation CreateCreateJobOperation(string jobId, string status, PipelineResponse response)
/// <summary>
/// Get FineTuningJob for a previously started fine-tuning job.
///
/// [Learn more about fine-tuning](/docs/guides/fine-tuning)
/// </summary>
/// <param name="JobId"> The ID of the fine-tuning job. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
public override FineTuningJob GetJob(string JobId, CancellationToken cancellationToken = default)
{
return new AzureFineTuningJobOperation(Pipeline, _endpoint, jobId, status, response, _apiVersion);
return AzureFineTuningJob.Rehydrate(this, JobId, cancellationToken.ToRequestOptions());
}

/// <summary>
/// Get FineTuningJob for a previously started fine-tuning job.
///
/// [Learn more about fine-tuning](/docs/guides/fine-tuning)
/// </summary>
/// <param name="JobId"> The ID of the fine-tuning job. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
public override async Task<FineTuningJob> GetJobAsync(string JobId, CancellationToken cancellationToken = default)
{
return await AzureFineTuningJob.RehydrateAsync(this, JobId, cancellationToken.ToRequestOptions()).ConfigureAwait(false);
}

//public override AsyncCollectionResult<AzureFineTuningJob> GetJobsAsync(FineTuningJobCollectionOptions options = default, CancellationToken cancellationToken = default)
//{
// options ??= new FineTuningJobCollectionOptions();
// AsyncCollectionResult<AzureFineTuningJob> jobs = (AsyncCollectionResult<AzureFineTuningJob>)GetJobsAsync(options.AfterJobId, options.PageSize, cancellationToken.ToRequestOptions());
// return (AsyncCollectionResult<AzureFineTuningJob>)jobs;
//}

[Experimental("OPENAI001")]
internal override FineTuningJob CreateJobFromResponse(PipelineResponse response)
{
return new AzureFineTuningJob(Pipeline, _endpoint, response, _apiVersion);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ClientModel;
using System.ClientModel.Primitives;
using System.Diagnostics.CodeAnalysis;

#if !AZURE_OPENAI_GA

#nullable enable

namespace Azure.AI.OpenAI.FineTuning;

/// <summary>
/// A long-running operation for creating a new model from a given dataset.
/// </summary>
[Experimental("OPENAI001")]
internal partial class AzureFineTuningJob : FineTuningJob
{
private readonly PipelineMessageClassifier _deleteJobClassifier;
internal new readonly ClientPipeline _pipeline;
private readonly Uri _endpoint;
private readonly string _apiVersion;
internal new readonly FineTuningClient _client;

internal AzureFineTuningJob(
ClientPipeline pipeline,
Uri endpoint,
PipelineResponse response,
string apiVersion)
: base(pipeline, endpoint, response)
{
_pipeline = pipeline;
_endpoint = endpoint;
_apiVersion = apiVersion;
_client = new AzureFineTuningClient(_pipeline, _endpoint, null);

_deleteJobClassifier = PipelineMessageClassifier.Create(stackalloc ushort[] { 204 });

}

internal AzureFineTuningJob(
ClientPipeline pipeline,
Uri endpoint,
PipelineResponse response,
string apiVersion,
InternalFineTuningJob internalJob)
: base(pipeline, endpoint, internalJob, response)
{
_pipeline = pipeline;
_endpoint = endpoint;
_apiVersion = apiVersion;
_client = new AzureFineTuningClient(_pipeline, _endpoint, null);

_deleteJobClassifier = PipelineMessageClassifier.Create(stackalloc ushort[] { 204 });
}

[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<ClientResult> 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();

// TODO use this
internal PipelineMessage CancelPipelineMessage(string fineTuningJobId, RequestOptions? options)
=> new AzureOpenAIPipelineMessageBuilder(_pipeline, _endpoint, _apiVersion)
.WithMethod("POST")
.WithPath("fine_tuning", "jobs", fineTuningJobId, "cancel")
.WithAccept("application/json")
.WithOptions(options)
.Build();

/// <summary>
/// [Protocol Method] List the checkpoints for a fine-tuning job.
/// </summary>
/// <param name="after"> Identifier for the last checkpoint ID from the previous pagination request. </param>
/// <param name="limit"> Number of checkpoints to retrieve. </param>
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
public override AsyncCollectionResult GetCheckpointsAsync(string? after, int? limit, RequestOptions? options)
{
return new AsyncFineTuningCheckpointCollectionResult(this, options, limit, after);
}

/// <summary>
/// [Protocol Method] List the checkpoints for a fine-tuning job.
/// </summary>
/// <param name="after"> Identifier for the last checkpoint ID from the previous pagination request. </param>
/// <param name="limit"> Number of checkpoints to retrieve. </param>
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
internal override async Task<ClientResult> GetCheckpointsPageAsync(string? after, int? limit, RequestOptions? options)
{
using PipelineMessage message = GetCheckpointsPipelineMessage(JobId, after, limit, options);
return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
}

/// <summary>
/// [Protocol Method] List the checkpoints for a fine-tuning job.
/// </summary>
/// <param name="after"> Identifier for the last checkpoint ID from the previous pagination request. </param>
/// <param name="limit"> Number of checkpoints to retrieve. </param>
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
internal override ClientResult GetCheckpointsPage(string? after, int? limit, RequestOptions? options)
{
using PipelineMessage message = GetCheckpointsPipelineMessage(JobId, after, limit, options);
return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
}

internal PipelineMessage GetCheckpointsPipelineMessage(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 async Task<ClientResult> GetEventsPageAsync(string? after, int? limit, RequestOptions? options)
{
using PipelineMessage message = GetEventsPipelineMessage(JobId, after, limit, options);
return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
}

internal override ClientResult GetEventsPage(string? after, int? limit, RequestOptions? options)
{
using PipelineMessage message = GetEventsPipelineMessage(JobId, after, limit, options);
return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
}

internal PipelineMessage GetEventsPipelineMessage(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();
}

#endif
Loading
Loading