openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0-beta.12

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Custom/Batch/BatchClient.Protocol.cs

137lines · modecode

1using System;
2using System.ClientModel;
3using System.ClientModel.Primitives;
4using System.Threading.Tasks;
5
6namespace OpenAI.Batch;
7
8[CodeGenSuppress("RetrieveBatch", typeof(string), typeof(RequestOptions))]
9[CodeGenSuppress("RetrieveBatchAsync", typeof(string), typeof(RequestOptions))]
10public partial class BatchClient
11{
12 /// <summary>
13 /// [Protocol Method] Creates and executes a batch from an uploaded file of requests
14 /// </summary>
15 /// <param name="content"> The content to send as the body of the request. </param>
16 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
17 /// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception>
18 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
19 /// <returns> The response returned from the service. </returns>
20 public virtual async Task<ClientResult> CreateBatchAsync(BinaryContent content, RequestOptions options = null)
21 {
22 Argument.AssertNotNull(content, nameof(content));
23
24 using PipelineMessage message = CreateCreateBatchRequest(content, options);
25 return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
26 }
27
28 /// <summary>
29 /// [Protocol Method] Creates and executes a batch from an uploaded file of requests
30 /// </summary>
31 /// <param name="content"> The content to send as the body of the request. </param>
32 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
33 /// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception>
34 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
35 /// <returns> The response returned from the service. </returns>
36 public virtual ClientResult CreateBatch(BinaryContent content, RequestOptions options = null)
37 {
38 Argument.AssertNotNull(content, nameof(content));
39
40 using PipelineMessage message = CreateCreateBatchRequest(content, options);
41 return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
42 }
43
44 /// <summary>
45 /// [Protocol Method] List your organization's batches.
46 /// </summary>
47 /// <param name="after"> A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. </param>
48 /// <param name="limit"> A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. </param>
49 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
50 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
51 /// <returns> The response returned from the service. </returns>
52 public virtual AsyncCollectionResult GetBatchesAsync(string after, int? limit, RequestOptions options)
53 {
54 return new AsyncBatchCollectionResult(this, _pipeline, options, limit, after);
55 }
56
57 /// <summary>
58 /// [Protocol Method] List your organization's batches.
59 /// </summary>
60 /// <param name="after"> A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. </param>
61 /// <param name="limit"> A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. </param>
62 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
63 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
64 /// <returns> The response returned from the service. </returns>
65 public virtual CollectionResult GetBatches(string after, int? limit, RequestOptions options)
66 {
67 return new BatchCollectionResult(this, _pipeline, options, limit, after);
68 }
69
70 /// <summary>
71 /// [Protocol Method] Retrieves a batch.
72 /// </summary>
73 /// <param name="batchId"> The ID of the batch to retrieve. </param>
74 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
75 /// <exception cref="ArgumentNullException"> <paramref name="batchId"/> is null. </exception>
76 /// <exception cref="ArgumentException"> <paramref name="batchId"/> is an empty string, and was expected to be non-empty. </exception>
77 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
78 /// <returns> The response returned from the service. </returns>
79 public virtual async Task<ClientResult> GetBatchAsync(string batchId, RequestOptions options)
80 {
81 Argument.AssertNotNullOrEmpty(batchId, nameof(batchId));
82
83 using PipelineMessage message = CreateRetrieveBatchRequest(batchId, options);
84 return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
85 }
86
87 /// <summary>
88 /// [Protocol Method] Retrieves a batch.
89 /// </summary>
90 /// <param name="batchId"> The ID of the batch to retrieve. </param>
91 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
92 /// <exception cref="ArgumentNullException"> <paramref name="batchId"/> is null. </exception>
93 /// <exception cref="ArgumentException"> <paramref name="batchId"/> is an empty string, and was expected to be non-empty. </exception>
94 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
95 /// <returns> The response returned from the service. </returns>
96 public virtual ClientResult GetBatch(string batchId, RequestOptions options)
97 {
98 Argument.AssertNotNullOrEmpty(batchId, nameof(batchId));
99
100 using PipelineMessage message = CreateRetrieveBatchRequest(batchId, options);
101 return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
102 }
103
104 /// <summary>
105 /// [Protocol Method] Cancels an in-progress batch.
106 /// </summary>
107 /// <param name="batchId"> The ID of the batch to cancel. </param>
108 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
109 /// <exception cref="ArgumentNullException"> <paramref name="batchId"/> is null. </exception>
110 /// <exception cref="ArgumentException"> <paramref name="batchId"/> is an empty string, and was expected to be non-empty. </exception>
111 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
112 /// <returns> The response returned from the service. </returns>
113 public virtual async Task<ClientResult> CancelBatchAsync(string batchId, RequestOptions options)
114 {
115 Argument.AssertNotNullOrEmpty(batchId, nameof(batchId));
116
117 using PipelineMessage message = CreateCancelBatchRequest(batchId, options);
118 return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
119 }
120
121 /// <summary>
122 /// [Protocol Method] Cancels an in-progress batch.
123 /// </summary>
124 /// <param name="batchId"> The ID of the batch to cancel. </param>
125 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
126 /// <exception cref="ArgumentNullException"> <paramref name="batchId"/> is null. </exception>
127 /// <exception cref="ArgumentException"> <paramref name="batchId"/> is an empty string, and was expected to be non-empty. </exception>
128 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
129 /// <returns> The response returned from the service. </returns>
130 public virtual ClientResult CancelBatch(string batchId, RequestOptions options)
131 {
132 Argument.AssertNotNullOrEmpty(batchId, nameof(batchId));
133
134 using PipelineMessage message = CreateCancelBatchRequest(batchId, options);
135 return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
136 }
137}
138