openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.2.0-beta.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Custom/Batch/BatchClient.cs

86lines · modecode

1using System;
2using System.ClientModel;
3using System.ClientModel.Primitives;
4using System.Collections.Generic;
5using System.Diagnostics.CodeAnalysis;
6using System.Threading;
7
8namespace OpenAI.Batch;
9
10// CUSTOM:
11// - Renamed.
12// - Suppressed constructor that takes endpoint parameter; endpoint is now a property in the options class.
13// - Suppressed convenience methods for now.
14/// <summary> The service client for OpenAI batch operations. </summary>
15[Experimental("OPENAI001")]
16[CodeGenClient("Batches")]
17[CodeGenSuppress("BatchClient", typeof(ClientPipeline), typeof(ApiKeyCredential), typeof(Uri))]
18[CodeGenSuppress("CreateBatch", typeof(string), typeof(InternalCreateBatchRequestEndpoint), typeof(InternalBatchCompletionTimeframe), typeof(IDictionary<string, string>), typeof(CancellationToken))]
19[CodeGenSuppress("CreateBatchAsync", typeof(string), typeof(InternalCreateBatchRequestEndpoint), typeof(InternalBatchCompletionTimeframe), typeof(IDictionary<string, string>), typeof(CancellationToken))]
20[CodeGenSuppress("CreateBatch", typeof(BinaryContent), typeof(RequestOptions))]
21[CodeGenSuppress("CreateBatchAsync", typeof(BinaryContent), typeof(RequestOptions))]
22[CodeGenSuppress("RetrieveBatch", typeof(string), typeof(CancellationToken))]
23[CodeGenSuppress("RetrieveBatchAsync", typeof(string), typeof(CancellationToken))]
24[CodeGenSuppress("CancelBatch", typeof(string), typeof(CancellationToken))]
25[CodeGenSuppress("CancelBatchAsync", typeof(string), typeof(CancellationToken))]
26[CodeGenSuppress("CancelBatch", typeof(string), typeof(RequestOptions))]
27[CodeGenSuppress("CancelBatchAsync", typeof(string), typeof(RequestOptions))]
28[CodeGenSuppress("ListBatches", typeof(string), typeof(int?), typeof(CancellationToken))]
29[CodeGenSuppress("ListBatchesAsync", typeof(string), typeof(int?), typeof(CancellationToken))]
30public partial class BatchClient
31{
32 // CUSTOM: Added as a convenience.
33 /// <summary> Initializes a new instance of <see cref="BatchClient"/>. </summary>
34 /// <param name="apiKey"> The API key to authenticate with the service. </param>
35 /// <exception cref="ArgumentNullException"> <paramref name="apiKey"/> is null. </exception>
36 public BatchClient(string apiKey) : this(new ApiKeyCredential(apiKey), new OpenAIClientOptions())
37 {
38 }
39
40 // CUSTOM:
41 // - Used a custom pipeline.
42 // - Demoted the endpoint parameter to be a property in the options class.
43 /// <summary> Initializes a new instance of <see cref="BatchClient"/>. </summary>
44 /// <param name="credential"> The API key to authenticate with the service. </param>
45 /// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception>
46 public BatchClient(ApiKeyCredential credential) : this(credential, new OpenAIClientOptions())
47 {
48 }
49
50 /// <summary>
51 /// Initializes a new instance of <see cref="BatchClient"/> that will use an API key when authenticating.
52 /// </summary>
53 /// <param name="credential"> The API key used to authenticate with the service endpoint. </param>
54 /// <param name="options"> Additional options to customize the client. </param>
55 /// <exception cref="ArgumentNullException"> The provided <paramref name="credential"/> was null. </exception>
56 public BatchClient(ApiKeyCredential credential, OpenAIClientOptions options)
57 {
58 Argument.AssertNotNull(credential, nameof(credential));
59 options ??= new OpenAIClientOptions();
60
61 Pipeline = OpenAIClient.CreatePipeline(credential, options);
62 _endpoint = OpenAIClient.GetEndpoint(options);
63 }
64
65 // CUSTOM:
66 // - Used a custom pipeline.
67 // - Demoted the endpoint parameter to be a property in the options class.
68 // - Made protected.
69 /// <summary> Initializes a new instance of <see cref="BatchClient"/>. </summary>
70 /// <param name="pipeline"> The HTTP pipeline to send and receive REST requests and responses. </param>
71 /// <param name="options"> The options to configure the client. </param>
72 /// <exception cref="ArgumentNullException"> <paramref name="pipeline"/> is null. </exception>
73 protected internal BatchClient(ClientPipeline pipeline, OpenAIClientOptions options)
74 {
75 Argument.AssertNotNull(pipeline, nameof(pipeline));
76 options ??= new OpenAIClientOptions();
77
78 Pipeline = pipeline;
79 _endpoint = OpenAIClient.GetEndpoint(options);
80 }
81
82 internal virtual CreateBatchOperation CreateCreateBatchOperation(string batchId, string status, PipelineResponse response)
83 {
84 return new CreateBatchOperation(Pipeline, _endpoint, batchId, status, response);
85 }
86}
87