openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Custom/FineTuning/FineTuningClient.cs

90lines · modecode

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