openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0-beta.7

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
8public partial class BatchClient
9{
10 /// <summary>
11 /// [Protocol Method] Creates and executes a batch from an uploaded file of requests
12 /// </summary>
13 /// <param name="content"> The content to send as the body of the request. </param>
14 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
15 /// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception>
16 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
17 /// <returns> The response returned from the service. </returns>
18 public virtual async Task<ClientResult> CreateBatchAsync(BinaryContent content, RequestOptions options = null)
19 {
20 Argument.AssertNotNull(content, nameof(content));
21
22 using PipelineMessage message = CreateCreateBatchRequest(content, options);
23 return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
24 }
25
26 /// <summary>
27 /// [Protocol Method] Creates and executes a batch from an uploaded file of requests
28 /// </summary>
29 /// <param name="content"> The content to send as the body of the request. </param>
30 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
31 /// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception>
32 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
33 /// <returns> The response returned from the service. </returns>
34 public virtual ClientResult CreateBatch(BinaryContent content, RequestOptions options = null)
35 {
36 Argument.AssertNotNull(content, nameof(content));
37
38 using PipelineMessage message = CreateCreateBatchRequest(content, options);
39 return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
40 }
41
42 /// <summary>
43 /// [Protocol Method] List your organization's batches.
44 /// </summary>
45 /// <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>
46 /// <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>
47 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
48 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
49 /// <returns> The response returned from the service. </returns>
50 public virtual async Task<ClientResult> GetBatchesAsync(string after, int? limit, RequestOptions options)
51 {
52 using PipelineMessage message = CreateGetBatchesRequest(after, limit, options);
53 return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
54 }
55
56 /// <summary>
57 /// [Protocol Method] List your organization's batches.
58 /// </summary>
59 /// <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>
60 /// <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>
61 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
62 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
63 /// <returns> The response returned from the service. </returns>
64 public virtual ClientResult GetBatches(string after, int? limit, RequestOptions options)
65 {
66 using PipelineMessage message = CreateGetBatchesRequest(after, limit, options);
67 return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
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