openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.2.0-beta.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Custom/Files/OpenAIFileClient.Protocol.cs

339lines · modecode

1using System;
2using System.ClientModel;
3using System.ClientModel.Primitives;
4using System.ComponentModel;
5using System.Diagnostics.CodeAnalysis;
6using System.Threading.Tasks;
7
8namespace OpenAI.Files;
9
10[CodeGenSuppress("CreateFileAsync", typeof(BinaryContent), typeof(string), typeof(RequestOptions))]
11[CodeGenSuppress("CreateFile", typeof(BinaryContent), typeof(string), typeof(RequestOptions))]
12[CodeGenSuppress("ListFilesAsync", typeof(string), typeof(RequestOptions))]
13[CodeGenSuppress("ListFiles", typeof(string), typeof(RequestOptions))]
14[CodeGenSuppress("RetrieveFileAsync", typeof(string), typeof(RequestOptions))]
15[CodeGenSuppress("RetrieveFile", typeof(string), typeof(RequestOptions))]
16[CodeGenSuppress("DeleteFileAsync", typeof(string), typeof(RequestOptions))]
17[CodeGenSuppress("DeleteFile", typeof(string), typeof(RequestOptions))]
18[CodeGenSuppress("DownloadFileAsync", typeof(string), typeof(RequestOptions))]
19[CodeGenSuppress("DownloadFile", typeof(string), typeof(RequestOptions))]
20public partial class OpenAIFileClient
21{
22 /// <summary>
23 /// [Protocol Method] Upload a file that can be used across various endpoints. The size of all the files uploaded by
24 /// one organization can be up to 100 GB.
25 ///
26 /// The size of individual files can be a maximum of 512 MB or 2 million tokens for Assistants. See
27 /// the <see href="https://platform.openai.com/docs/assistants/tools">Assistants Tools guide</see> to
28 /// learn more about the types of files supported. The Fine-tuning API only supports `.jsonl` files.
29 ///
30 /// Please <see href="https://help.openai.com/">contact us</see> if you need to increase these
31 /// storage limits.
32 /// </summary>
33 /// <param name="content"> The content to send as the body of the request. </param>
34 /// <param name="contentType"> The content type of the request. </param>
35 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
36 /// <exception cref="ArgumentNullException"> <paramref name="content"/> or <paramref name="contentType"/> is null. </exception>
37 /// <exception cref="ArgumentException"> <paramref name="contentType"/> is an empty string, and was expected to be non-empty. </exception>
38 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
39 /// <returns> The response returned from the service. </returns>
40 [EditorBrowsable(EditorBrowsableState.Never)]
41 public virtual async Task<ClientResult> UploadFileAsync(BinaryContent content, string contentType, RequestOptions options = null)
42 {
43 Argument.AssertNotNull(content, nameof(content));
44 Argument.AssertNotNullOrEmpty(contentType, nameof(contentType));
45
46 using PipelineMessage message = CreateCreateFileRequest(content, contentType, options);
47 return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
48 }
49
50 /// <summary>
51 /// [Protocol Method] Upload a file that can be used across various endpoints. The size of all the files uploaded by
52 /// one organization can be up to 100 GB.
53 ///
54 /// The size of individual files can be a maximum of 512 MB or 2 million tokens for Assistants. See
55 /// the <see href="https://platform.openai.com/docs/assistants/tools">Assistants Tools guide</see> to
56 /// learn more about the types of files supported. The Fine-tuning API only supports `.jsonl` files.
57 ///
58 /// Please <see href="https://help.openai.com/">contact us</see> if you need to increase these
59 /// storage limits.
60 /// </summary>
61 /// <param name="content"> The content to send as the body of the request. </param>
62 /// <param name="contentType"> The content type of the request. </param>
63 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
64 /// <exception cref="ArgumentNullException"> <paramref name="content"/> or <paramref name="contentType"/> is null. </exception>
65 /// <exception cref="ArgumentException"> <paramref name="contentType"/> is an empty string, and was expected to be non-empty. </exception>
66 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
67 /// <returns> The response returned from the service. </returns>
68 [EditorBrowsable(EditorBrowsableState.Never)]
69 public virtual ClientResult UploadFile(BinaryContent content, string contentType, RequestOptions options = null)
70 {
71 Argument.AssertNotNull(content, nameof(content));
72 Argument.AssertNotNullOrEmpty(contentType, nameof(contentType));
73
74 using PipelineMessage message = CreateCreateFileRequest(content, contentType, options);
75 return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
76 }
77
78 /// <summary>
79 /// [Protocol Method] Retrieves a list of files that belong to the user's organization.
80 /// </summary>
81 /// <param name="purpose"> Only return files with the given purpose. </param>
82 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
83 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
84 /// <returns> The response returned from the service. </returns>
85 [EditorBrowsable(EditorBrowsableState.Never)]
86 public virtual async Task<ClientResult> GetFilesAsync(string purpose, RequestOptions options)
87 {
88 using PipelineMessage message = CreateListFilesRequest(purpose, options);
89 return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
90 }
91
92 /// <summary>
93 /// [Protocol Method] Retrieves a list of files that belong to the user's organization.
94 /// </summary>
95 /// <param name="purpose"> Only return files with the given purpose. </param>
96 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
97 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
98 /// <returns> The response returned from the service. </returns>
99 [EditorBrowsable(EditorBrowsableState.Never)]
100 public virtual ClientResult GetFiles(string purpose, RequestOptions options)
101 {
102 using PipelineMessage message = CreateListFilesRequest(purpose, options);
103 return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
104 }
105
106 /// <summary>
107 /// [Protocol Method] Retrieves information about a specified file.
108 /// </summary>
109 /// <param name="fileId"> The ID of the file to retrieve. </param>
110 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
111 /// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception>
112 /// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception>
113 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
114 /// <returns> The response returned from the service. </returns>
115 [EditorBrowsable(EditorBrowsableState.Never)]
116 public virtual async Task<ClientResult> GetFileAsync(string fileId, RequestOptions options)
117 {
118 Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
119
120 using PipelineMessage message = CreateRetrieveFileRequest(fileId, options);
121 return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
122 }
123
124 /// <summary>
125 /// [Protocol Method] Retrieves information about a specified file.
126 /// </summary>
127 /// <param name="fileId"> The ID of the file to retrieve. </param>
128 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
129 /// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception>
130 /// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception>
131 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
132 /// <returns> The response returned from the service. </returns>
133 [EditorBrowsable(EditorBrowsableState.Never)]
134 public virtual ClientResult GetFile(string fileId, RequestOptions options)
135 {
136 Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
137
138 using PipelineMessage message = CreateRetrieveFileRequest(fileId, options);
139 return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
140 }
141
142 /// <summary>
143 /// [Protocol Method] Deletes a previously uploaded file.
144 /// </summary>
145 /// <param name="fileId"> The ID of the file to delete. </param>
146 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
147 /// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception>
148 /// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception>
149 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
150 /// <returns> The response returned from the service. </returns>
151 [EditorBrowsable(EditorBrowsableState.Never)]
152 public virtual async Task<ClientResult> DeleteFileAsync(string fileId, RequestOptions options)
153 {
154 Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
155
156 using PipelineMessage message = CreateDeleteFileRequest(fileId, options);
157 return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
158 }
159
160 /// <summary>
161 /// [Protocol Method] Deletes a previously uploaded file.
162 /// </summary>
163 /// <param name="fileId"> The ID of the file to delete. </param>
164 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
165 /// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception>
166 /// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception>
167 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
168 /// <returns> The response returned from the service. </returns>
169 [EditorBrowsable(EditorBrowsableState.Never)]
170 public virtual ClientResult DeleteFile(string fileId, RequestOptions options)
171 {
172 Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
173
174 using PipelineMessage message = CreateDeleteFileRequest(fileId, options);
175 return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
176 }
177
178 /// <summary>
179 /// [Protocol Method] Downloads the binary content of the specified file.
180 /// </summary>
181 /// <param name="fileId"> The ID of the file to download. </param>
182 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
183 /// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception>
184 /// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception>
185 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
186 /// <returns> The response returned from the service. </returns>
187 [EditorBrowsable(EditorBrowsableState.Never)]
188 public virtual async Task<ClientResult> DownloadFileAsync(string fileId, RequestOptions options)
189 {
190 Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
191
192 using PipelineMessage message = CreateDownloadFileRequest(fileId, options);
193 return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
194 }
195
196 /// <summary>
197 /// [Protocol Method] Downloads the binary content of the specified file.
198 /// </summary>
199 /// <param name="fileId"> The ID of the file to download. </param>
200 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
201 /// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception>
202 /// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception>
203 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
204 /// <returns> The response returned from the service. </returns>
205 [EditorBrowsable(EditorBrowsableState.Never)]
206 public virtual ClientResult DownloadFile(string fileId, RequestOptions options)
207 {
208 Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
209
210 using PipelineMessage message = CreateDownloadFileRequest(fileId, options);
211 return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
212 }
213
214 /// <summary>
215 /// [Protocol Method] Creates an intermediate upload to which data can be added in chunks of bytes. An upload
216 /// can accept at most 8 GB in total and expires an hour after it is created.
217 /// </summary>
218 /// <param name="content"> The content to send as the body of the request. </param>
219 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
220 /// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception>
221 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
222 /// <returns> The response returned from the service. </returns>
223 [Experimental("OPENAI001")]
224 public virtual async Task<ClientResult> CreateUploadAsync(BinaryContent content, RequestOptions options = null)
225 {
226 return await _internalUploadsClient.CreateUploadAsync(content, options).ConfigureAwait(false);
227 }
228
229 /// <summary>
230 /// [Protocol Method] Creates an intermediate upload to which data can be added in chunks of bytes. An upload
231 /// can accept at most 8 GB in total and expires an hour after it is created.
232 /// </summary>
233 /// <param name="content"> The content to send as the body of the request. </param>
234 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
235 /// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception>
236 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
237 /// <returns> The response returned from the service. </returns>
238 [Experimental("OPENAI001")]
239 public virtual ClientResult CreateUpload(BinaryContent content, RequestOptions options = null)
240 {
241 return _internalUploadsClient.CreateUpload(content, options);
242 }
243
244 /// <summary>
245 /// [Protocol Method] Adds a chunk of bytes to an existing upload. Each part can contain at most 64 MB, while the
246 /// upload can accept at most 8 GB in total.
247 /// </summary>
248 /// <param name="uploadId"> The ID of the upload. </param>
249 /// <param name="content"> The content to send as the body of the request. </param>
250 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
251 /// <exception cref="ArgumentNullException"> <paramref name="uploadId"/> or <paramref name="content"/> is null. </exception>
252 /// <exception cref="ArgumentException"> <paramref name="uploadId"/> is an empty string, and was expected to be non-empty. </exception>
253 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
254 /// <returns> The response returned from the service. </returns>
255 [Experimental("OPENAI001")]
256 public virtual async Task<ClientResult> AddUploadPartAsync(string uploadId, BinaryContent content, string contentType, RequestOptions options = null)
257 {
258 return await _internalUploadsClient.AddUploadPartAsync(uploadId, content, contentType, options).ConfigureAwait(false);
259 }
260
261 /// <summary>
262 /// [Protocol Method] Adds a chunk of bytes to an existing upload. Each part can contain at most 64 MB, while the
263 /// upload can accept at most 8 GB in total.
264 /// </summary>
265 /// <param name="uploadId"> The ID of the upload. </param>
266 /// <param name="content"> The content to send as the body of the request. </param>
267 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
268 /// <exception cref="ArgumentNullException"> <paramref name="uploadId"/> or <paramref name="content"/> is null. </exception>
269 /// <exception cref="ArgumentException"> <paramref name="uploadId"/> is an empty string, and was expected to be non-empty. </exception>
270 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
271 /// <returns> The response returned from the service. </returns>
272 [Experimental("OPENAI001")]
273 public virtual ClientResult AddUploadPart(string uploadId, BinaryContent content, string contentType, RequestOptions options = null)
274 {
275 return _internalUploadsClient.AddUploadPart(uploadId, content, contentType, options);
276 }
277
278 /// <summary>
279 /// [Protocol Method] Completes an existing upload, creating a file ready to use.
280 /// </summary>
281 /// <param name="uploadId"> The ID of the upload. </param>
282 /// <param name="content"> The content to send as the body of the request. </param>
283 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
284 /// <exception cref="ArgumentNullException"> <paramref name="uploadId"/> or <paramref name="content"/> is null. </exception>
285 /// <exception cref="ArgumentException"> <paramref name="uploadId"/> is an empty string, and was expected to be non-empty. </exception>
286 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
287 /// <returns> The response returned from the service. </returns>
288 [Experimental("OPENAI001")]
289 public virtual async Task<ClientResult> CompleteUploadAsync(string uploadId, BinaryContent content, RequestOptions options = null)
290 {
291 return await _internalUploadsClient.CompleteUploadAsync(uploadId, content, options).ConfigureAwait(false);
292 }
293
294 /// <summary>
295 /// [Protocol Method] Completes an existing upload, creating a file ready to use.
296 /// </summary>
297 /// <param name="uploadId"> The ID of the upload. </param>
298 /// <param name="content"> The content to send as the body of the request. </param>
299 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
300 /// <exception cref="ArgumentNullException"> <paramref name="uploadId"/> or <paramref name="content"/> is null. </exception>
301 /// <exception cref="ArgumentException"> <paramref name="uploadId"/> is an empty string, and was expected to be non-empty. </exception>
302 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
303 /// <returns> The response returned from the service. </returns>
304 [Experimental("OPENAI001")]
305 public virtual ClientResult CompleteUpload(string uploadId, BinaryContent content, RequestOptions options = null)
306 {
307 return _internalUploadsClient.CompleteUpload(uploadId, content, options);
308 }
309
310 /// <summary>
311 /// [Protocol Method] Cancels an existing upload.
312 /// </summary>
313 /// <param name="uploadId"> The ID of the upload. </param>
314 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
315 /// <exception cref="ArgumentNullException"> <paramref name="uploadId"/> is null. </exception>
316 /// <exception cref="ArgumentException"> <paramref name="uploadId"/> is an empty string, and was expected to be non-empty. </exception>
317 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
318 /// <returns> The response returned from the service. </returns>
319 [Experimental("OPENAI001")]
320 public virtual async Task<ClientResult> CancelUploadAsync(string uploadId, RequestOptions options = null)
321 {
322 return await _internalUploadsClient.CancelUploadAsync(uploadId, options).ConfigureAwait(false);
323 }
324
325 /// <summary>
326 /// [Protocol Method] Cancels an existing upload.
327 /// </summary>
328 /// <param name="uploadId"> The ID of the upload. </param>
329 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
330 /// <exception cref="ArgumentNullException"> <paramref name="uploadId"/> is null. </exception>
331 /// <exception cref="ArgumentException"> <paramref name="uploadId"/> is an empty string, and was expected to be non-empty. </exception>
332 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
333 /// <returns> The response returned from the service. </returns>
334 [Experimental("OPENAI001")]
335 public virtual ClientResult CancelUpload(string uploadId, RequestOptions options = null)
336 {
337 return _internalUploadsClient.CancelUpload(uploadId, options);
338 }
339}
340