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 · modeblame

58f93c8dShivangiReja2 years ago1using System;
9f9f2936Jose Arriaga Maldonado2 years ago2using System.ClientModel;
3using System.ClientModel.Primitives;
4using System.ComponentModel;
2ab1a942Jose Arriaga Maldonado1 years ago5using System.Diagnostics.CodeAnalysis;
9f9f2936Jose Arriaga Maldonado2 years ago6using 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))]
e0fee603Jose Arriaga Maldonado1 years ago12[CodeGenSuppress("ListFilesAsync", typeof(string), typeof(RequestOptions))]
13[CodeGenSuppress("ListFiles", typeof(string), typeof(RequestOptions))]
9f9f2936Jose Arriaga Maldonado2 years ago14[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))]
31c2ba63Jose Arriaga Maldonado1 years ago20public partial class OpenAIFileClient
9f9f2936Jose Arriaga Maldonado2 years ago21{
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)]
41public virtual async Task<ClientResult> UploadFileAsync(BinaryContent content, string contentType, RequestOptions options = null)
42{
43Argument.AssertNotNull(content, nameof(content));
44Argument.AssertNotNullOrEmpty(contentType, nameof(contentType));
45
46using PipelineMessage message = CreateCreateFileRequest(content, contentType, options);
e0fee603Jose Arriaga Maldonado1 years ago47return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
9f9f2936Jose Arriaga Maldonado2 years ago48}
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)]
69public virtual ClientResult UploadFile(BinaryContent content, string contentType, RequestOptions options = null)
70{
71Argument.AssertNotNull(content, nameof(content));
72Argument.AssertNotNullOrEmpty(contentType, nameof(contentType));
73
74using PipelineMessage message = CreateCreateFileRequest(content, contentType, options);
e0fee603Jose Arriaga Maldonado1 years ago75return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
9f9f2936Jose Arriaga Maldonado2 years ago76}
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)]
86public virtual async Task<ClientResult> GetFilesAsync(string purpose, RequestOptions options)
87{
e0fee603Jose Arriaga Maldonado1 years ago88using PipelineMessage message = CreateListFilesRequest(purpose, options);
89return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
9f9f2936Jose Arriaga Maldonado2 years ago90}
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)]
100public virtual ClientResult GetFiles(string purpose, RequestOptions options)
101{
e0fee603Jose Arriaga Maldonado1 years ago102using PipelineMessage message = CreateListFilesRequest(purpose, options);
103return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
9f9f2936Jose Arriaga Maldonado2 years ago104}
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)]
116public virtual async Task<ClientResult> GetFileAsync(string fileId, RequestOptions options)
117{
118Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
119
120using PipelineMessage message = CreateRetrieveFileRequest(fileId, options);
e0fee603Jose Arriaga Maldonado1 years ago121return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
9f9f2936Jose Arriaga Maldonado2 years ago122}
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)]
134public virtual ClientResult GetFile(string fileId, RequestOptions options)
135{
136Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
137
138using PipelineMessage message = CreateRetrieveFileRequest(fileId, options);
e0fee603Jose Arriaga Maldonado1 years ago139return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
9f9f2936Jose Arriaga Maldonado2 years ago140}
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)]
152public virtual async Task<ClientResult> DeleteFileAsync(string fileId, RequestOptions options)
153{
154Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
155
156using PipelineMessage message = CreateDeleteFileRequest(fileId, options);
e0fee603Jose Arriaga Maldonado1 years ago157return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
9f9f2936Jose Arriaga Maldonado2 years ago158}
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)]
170public virtual ClientResult DeleteFile(string fileId, RequestOptions options)
171{
172Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
173
174using PipelineMessage message = CreateDeleteFileRequest(fileId, options);
e0fee603Jose Arriaga Maldonado1 years ago175return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
9f9f2936Jose Arriaga Maldonado2 years ago176}
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)]
188public virtual async Task<ClientResult> DownloadFileAsync(string fileId, RequestOptions options)
189{
190Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
191
192using PipelineMessage message = CreateDownloadFileRequest(fileId, options);
e0fee603Jose Arriaga Maldonado1 years ago193return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
9f9f2936Jose Arriaga Maldonado2 years ago194}
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)]
206public virtual ClientResult DownloadFile(string fileId, RequestOptions options)
207{
208Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
209
210using PipelineMessage message = CreateDownloadFileRequest(fileId, options);
e0fee603Jose Arriaga Maldonado1 years ago211return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
9f9f2936Jose Arriaga Maldonado2 years ago212}
2ab1a942Jose Arriaga Maldonado1 years ago213
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")]
224public virtual async Task<ClientResult> CreateUploadAsync(BinaryContent content, RequestOptions options = null)
225{
226return 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")]
239public virtual ClientResult CreateUpload(BinaryContent content, RequestOptions options = null)
240{
241return _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>
e0fee603Jose Arriaga Maldonado1 years ago251/// <exception cref="ArgumentNullException"> <paramref name="uploadId"/> or <paramref name="content"/> is null. </exception>
2ab1a942Jose Arriaga Maldonado1 years ago252/// <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")]
256public virtual async Task<ClientResult> AddUploadPartAsync(string uploadId, BinaryContent content, string contentType, RequestOptions options = null)
257{
258return 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>
e0fee603Jose Arriaga Maldonado1 years ago268/// <exception cref="ArgumentNullException"> <paramref name="uploadId"/> or <paramref name="content"/> is null. </exception>
2ab1a942Jose Arriaga Maldonado1 years ago269/// <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")]
273public virtual ClientResult AddUploadPart(string uploadId, BinaryContent content, string contentType, RequestOptions options = null)
274{
275return _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>
e0fee603Jose Arriaga Maldonado1 years ago284/// <exception cref="ArgumentNullException"> <paramref name="uploadId"/> or <paramref name="content"/> is null. </exception>
2ab1a942Jose Arriaga Maldonado1 years ago285/// <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")]
289public virtual async Task<ClientResult> CompleteUploadAsync(string uploadId, BinaryContent content, RequestOptions options = null)
290{
291return 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>
e0fee603Jose Arriaga Maldonado1 years ago300/// <exception cref="ArgumentNullException"> <paramref name="uploadId"/> or <paramref name="content"/> is null. </exception>
2ab1a942Jose Arriaga Maldonado1 years ago301/// <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")]
305public virtual ClientResult CompleteUpload(string uploadId, BinaryContent content, RequestOptions options = null)
306{
307return _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>
e0fee603Jose Arriaga Maldonado1 years ago315/// <exception cref="ArgumentNullException"> <paramref name="uploadId"/> is null. </exception>
2ab1a942Jose Arriaga Maldonado1 years ago316/// <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")]
320public virtual async Task<ClientResult> CancelUploadAsync(string uploadId, RequestOptions options = null)
321{
322return 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>
e0fee603Jose Arriaga Maldonado1 years ago330/// <exception cref="ArgumentNullException"> <paramref name="uploadId"/> is null. </exception>
2ab1a942Jose Arriaga Maldonado1 years ago331/// <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")]
335public virtual ClientResult CancelUpload(string uploadId, RequestOptions options = null)
336{
337return _internalUploadsClient.CancelUpload(uploadId, options);
338}
9f9f2936Jose Arriaga Maldonado2 years ago339}