openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/FineTuning/FineTuningClient.cs
85lines · modecode
| 1 | using System; |
| 2 | using System.ClientModel; |
| 3 | using System.ClientModel.Primitives; |
| 4 | using System.Diagnostics.CodeAnalysis; |
| 5 | using System.Threading; |
| 6 | |
| 7 | namespace OpenAI.FineTuning; |
| 8 | |
| 9 | // CUSTOM: |
| 10 | // - Renamed. |
| 11 | // - Suppressed constructor that takes endpoint parameter; endpoint is now a property in the options class. |
| 12 | // - Suppressed convenience methods for now. |
| 13 | /// <summary> The service client for OpenAI fine-tuning operations. </summary> |
| 14 | [Experimental("OPENAI001")] |
| 15 | [CodeGenType("FineTuning")] |
| 16 | [CodeGenSuppress("FineTuningClient", typeof(ClientPipeline), typeof(Uri))] |
| 17 | [CodeGenSuppress("CreateFineTuningJobAsync", typeof(FineTuningOptions), typeof(CancellationToken))] |
| 18 | [CodeGenSuppress("CreateFineTuningJob", typeof(FineTuningOptions), typeof(CancellationToken))] |
| 19 | [CodeGenSuppress("ListPaginatedFineTuningJobsAsync", typeof(string), typeof(int?), typeof(CancellationToken))] |
| 20 | [CodeGenSuppress("ListPaginatedFineTuningJobs", typeof(string), typeof(int?), typeof(CancellationToken))] |
| 21 | [CodeGenSuppress("RetrieveFineTuningJobAsync", typeof(string), typeof(CancellationToken))] |
| 22 | [CodeGenSuppress("RetrieveFineTuningJob", typeof(string), typeof(CancellationToken))] |
| 23 | [CodeGenSuppress("CancelFineTuningJobAsync", typeof(string), typeof(CancellationToken))] |
| 24 | [CodeGenSuppress("CancelFineTuningJob", typeof(string), typeof(CancellationToken))] |
| 25 | [CodeGenSuppress("ListFineTuningEventsAsync", typeof(string), typeof(string), typeof(int?), typeof(CancellationToken))] |
| 26 | [CodeGenSuppress("ListFineTuningEvents", typeof(string), typeof(string), typeof(int?), typeof(CancellationToken))] |
| 27 | [CodeGenSuppress("ListFineTuningJobCheckpointsAsync", typeof(string), typeof(string), typeof(int?), typeof(CancellationToken))] |
| 28 | [CodeGenSuppress("ListFineTuningJobCheckpoints", typeof(string), typeof(string), typeof(int?), typeof(CancellationToken))] |
| 29 | public partial class FineTuningClient |
| 30 | { |
| 31 | // CUSTOM: Added as a convenience. |
| 32 | /// <summary> Initializes a new instance of <see cref="FineTuningClient"/>. </summary> |
| 33 | /// <param name="apiKey"> The API key to authenticate with the service. </param> |
| 34 | /// <exception cref="ArgumentNullException"> <paramref name="apiKey"/> is null. </exception> |
| 35 | public FineTuningClient(string apiKey) : this(new ApiKeyCredential(apiKey), new OpenAIClientOptions()) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | // CUSTOM: |
| 40 | // - Used a custom pipeline. |
| 41 | // - Demoted the endpoint parameter to be a property in the options class. |
| 42 | /// <summary> Initializes a new instance of <see cref="FineTuningClient"/>. </summary> |
| 43 | /// <param name="credential"> The API key to authenticate with the service. </param> |
| 44 | /// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception> |
| 45 | public FineTuningClient(ApiKeyCredential credential) : this(credential, new OpenAIClientOptions()) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | /// <summary> |
| 50 | /// Initializes a new instance of <see cref="FineTuningClient"/> that will use an API key when authenticating. |
| 51 | /// </summary> |
| 52 | /// <param name="credential"> The API key used to authenticate with the service endpoint. </param> |
| 53 | /// <param name="options"> Additional options to customize the client. </param> |
| 54 | /// <exception cref="ArgumentNullException"> The provided <paramref name="credential"/> was null. </exception> |
| 55 | public FineTuningClient(ApiKeyCredential credential, OpenAIClientOptions options) |
| 56 | { |
| 57 | Argument.AssertNotNull(credential, nameof(credential)); |
| 58 | options ??= new OpenAIClientOptions(); |
| 59 | |
| 60 | Pipeline = OpenAIClient.CreatePipeline(credential, options); |
| 61 | _endpoint = OpenAIClient.GetEndpoint(options); |
| 62 | } |
| 63 | |
| 64 | // CUSTOM: |
| 65 | // - Used a custom pipeline. |
| 66 | // - Demoted the endpoint parameter to be a property in the options class. |
| 67 | // - Made protected. |
| 68 | /// <summary> Initializes a new instance of <see cref="FineTuningClient"/>. </summary> |
| 69 | /// <param name="pipeline"> The HTTP pipeline to send and receive REST requests and responses. </param> |
| 70 | /// <param name="options"> The options to configure the client. </param> |
| 71 | /// <exception cref="ArgumentNullException"> <paramref name="pipeline"/> is null. </exception> |
| 72 | protected internal FineTuningClient(ClientPipeline pipeline, OpenAIClientOptions options) |
| 73 | { |
| 74 | Argument.AssertNotNull(pipeline, nameof(pipeline)); |
| 75 | options ??= new OpenAIClientOptions(); |
| 76 | |
| 77 | Pipeline = pipeline; |
| 78 | _endpoint = OpenAIClient.GetEndpoint(options); |
| 79 | } |
| 80 | |
| 81 | internal virtual FineTuningJobOperation CreateCreateJobOperation(string jobId, string status, PipelineResponse response) |
| 82 | { |
| 83 | return new FineTuningJobOperation(Pipeline, _endpoint, jobId, status, response); |
| 84 | } |
| 85 | } |
| 86 | |