openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0-beta.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Custom/Files/FileClient.Protocol.cs

212lines · modeblame

9f9f2936Jose Arriaga Maldonado2 years ago1using System;
2using System.ClientModel;
3using System.ClientModel.Primitives;
4using System.ComponentModel;
5using System.Threading.Tasks;
6
7namespace OpenAI.Files;
8
9[CodeGenSuppress("CreateFileAsync", typeof(BinaryContent), typeof(string), typeof(RequestOptions))]
10[CodeGenSuppress("CreateFile", typeof(BinaryContent), typeof(string), typeof(RequestOptions))]
11[CodeGenSuppress("GetFilesAsync", typeof(string), typeof(RequestOptions))]
12[CodeGenSuppress("GetFiles", typeof(string), typeof(RequestOptions))]
13[CodeGenSuppress("RetrieveFileAsync", typeof(string), typeof(RequestOptions))]
14[CodeGenSuppress("RetrieveFile", typeof(string), typeof(RequestOptions))]
15[CodeGenSuppress("DeleteFileAsync", typeof(string), typeof(RequestOptions))]
16[CodeGenSuppress("DeleteFile", typeof(string), typeof(RequestOptions))]
17[CodeGenSuppress("DownloadFileAsync", typeof(string), typeof(RequestOptions))]
18[CodeGenSuppress("DownloadFile", typeof(string), typeof(RequestOptions))]
19public partial class FileClient
20{
21/// <summary>
22/// [Protocol Method] Upload a file that can be used across various endpoints. The size of all the files uploaded by
23/// one organization can be up to 100 GB.
24///
25/// The size of individual files can be a maximum of 512 MB or 2 million tokens for Assistants. See
26/// the <see href="https://platform.openai.com/docs/assistants/tools">Assistants Tools guide</see> to
27/// learn more about the types of files supported. The Fine-tuning API only supports `.jsonl` files.
28///
29/// Please <see href="https://help.openai.com/">contact us</see> if you need to increase these
30/// storage limits.
31/// </summary>
32/// <param name="content"> The content to send as the body of the request. </param>
33/// <param name="contentType"> The content type of the request. </param>
34/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
35/// <exception cref="ArgumentNullException"> <paramref name="content"/> or <paramref name="contentType"/> is null. </exception>
36/// <exception cref="ArgumentException"> <paramref name="contentType"/> is an empty string, and was expected to be non-empty. </exception>
37/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
38/// <returns> The response returned from the service. </returns>
39[EditorBrowsable(EditorBrowsableState.Never)]
40public virtual async Task<ClientResult> UploadFileAsync(BinaryContent content, string contentType, RequestOptions options = null)
41{
42Argument.AssertNotNull(content, nameof(content));
43Argument.AssertNotNullOrEmpty(contentType, nameof(contentType));
44
45using PipelineMessage message = CreateCreateFileRequest(content, contentType, options);
46return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
47}
48
49/// <summary>
50/// [Protocol Method] Upload a file that can be used across various endpoints. The size of all the files uploaded by
51/// one organization can be up to 100 GB.
52///
53/// The size of individual files can be a maximum of 512 MB or 2 million tokens for Assistants. See
54/// the <see href="https://platform.openai.com/docs/assistants/tools">Assistants Tools guide</see> to
55/// learn more about the types of files supported. The Fine-tuning API only supports `.jsonl` files.
56///
57/// Please <see href="https://help.openai.com/">contact us</see> if you need to increase these
58/// storage limits.
59/// </summary>
60/// <param name="content"> The content to send as the body of the request. </param>
61/// <param name="contentType"> The content type of the request. </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="ArgumentNullException"> <paramref name="content"/> or <paramref name="contentType"/> is null. </exception>
64/// <exception cref="ArgumentException"> <paramref name="contentType"/> is an empty string, and was expected to be non-empty. </exception>
65/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
66/// <returns> The response returned from the service. </returns>
67[EditorBrowsable(EditorBrowsableState.Never)]
68public virtual ClientResult UploadFile(BinaryContent content, string contentType, RequestOptions options = null)
69{
70Argument.AssertNotNull(content, nameof(content));
71Argument.AssertNotNullOrEmpty(contentType, nameof(contentType));
72
73using PipelineMessage message = CreateCreateFileRequest(content, contentType, options);
74return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
75}
76
77/// <summary>
78/// [Protocol Method] Retrieves a list of files that belong to the user's organization.
79/// </summary>
80/// <param name="purpose"> Only return files with the given purpose. </param>
81/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
82/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
83/// <returns> The response returned from the service. </returns>
84[EditorBrowsable(EditorBrowsableState.Never)]
85public virtual async Task<ClientResult> GetFilesAsync(string purpose, RequestOptions options)
86{
87using PipelineMessage message = CreateGetFilesRequest(purpose, options);
88return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
89}
90
91/// <summary>
92/// [Protocol Method] Retrieves a list of files that belong to the user's organization.
93/// </summary>
94/// <param name="purpose"> Only return files with the given purpose. </param>
95/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
96/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
97/// <returns> The response returned from the service. </returns>
98[EditorBrowsable(EditorBrowsableState.Never)]
99public virtual ClientResult GetFiles(string purpose, RequestOptions options)
100{
101using PipelineMessage message = CreateGetFilesRequest(purpose, options);
102return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
103}
104
105/// <summary>
106/// [Protocol Method] Retrieves information about a specified file.
107/// </summary>
108/// <param name="fileId"> The ID of the file to retrieve. </param>
109/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
110/// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception>
111/// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception>
112/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
113/// <returns> The response returned from the service. </returns>
114[EditorBrowsable(EditorBrowsableState.Never)]
115public virtual async Task<ClientResult> GetFileAsync(string fileId, RequestOptions options)
116{
117Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
118
119using PipelineMessage message = CreateRetrieveFileRequest(fileId, options);
120return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
121}
122
123/// <summary>
124/// [Protocol Method] Retrieves information about a specified file.
125/// </summary>
126/// <param name="fileId"> The ID of the file to retrieve. </param>
127/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
128/// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception>
129/// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception>
130/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
131/// <returns> The response returned from the service. </returns>
132[EditorBrowsable(EditorBrowsableState.Never)]
133public virtual ClientResult GetFile(string fileId, RequestOptions options)
134{
135Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
136
137using PipelineMessage message = CreateRetrieveFileRequest(fileId, options);
138return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
139}
140
141/// <summary>
142/// [Protocol Method] Deletes a previously uploaded file.
143/// </summary>
144/// <param name="fileId"> The ID of the file to delete. </param>
145/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
146/// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception>
147/// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception>
148/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
149/// <returns> The response returned from the service. </returns>
150[EditorBrowsable(EditorBrowsableState.Never)]
151public virtual async Task<ClientResult> DeleteFileAsync(string fileId, RequestOptions options)
152{
153Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
154
155using PipelineMessage message = CreateDeleteFileRequest(fileId, options);
156return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
157}
158
159/// <summary>
160/// [Protocol Method] Deletes a previously uploaded file.
161/// </summary>
162/// <param name="fileId"> The ID of the file to delete. </param>
163/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
164/// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception>
165/// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception>
166/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
167/// <returns> The response returned from the service. </returns>
168[EditorBrowsable(EditorBrowsableState.Never)]
169public virtual ClientResult DeleteFile(string fileId, RequestOptions options)
170{
171Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
172
173using PipelineMessage message = CreateDeleteFileRequest(fileId, options);
174return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
175}
176
177/// <summary>
178/// [Protocol Method] Downloads the binary content of the specified file.
179/// </summary>
180/// <param name="fileId"> The ID of the file to download. </param>
181/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
182/// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception>
183/// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception>
184/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
185/// <returns> The response returned from the service. </returns>
186[EditorBrowsable(EditorBrowsableState.Never)]
187public virtual async Task<ClientResult> DownloadFileAsync(string fileId, RequestOptions options)
188{
189Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
190
191using PipelineMessage message = CreateDownloadFileRequest(fileId, options);
192return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
193}
194
195/// <summary>
196/// [Protocol Method] Downloads the binary content of the specified file.
197/// </summary>
198/// <param name="fileId"> The ID of the file to download. </param>
199/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
200/// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception>
201/// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception>
202/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
203/// <returns> The response returned from the service. </returns>
204[EditorBrowsable(EditorBrowsableState.Never)]
205public virtual ClientResult DownloadFile(string fileId, RequestOptions options)
206{
207Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
208
209using PipelineMessage message = CreateDownloadFileRequest(fileId, options);
210return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
211}
212}