openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Files/OpenAIFileClient.cs
336lines · modeblame
9f9f2936Jose Arriaga Maldonado2 years ago | 1 | using System; |
| 2 | using System.ClientModel; | |
| 3 | using System.ClientModel.Primitives; | |
3613b6a0Jose Arriaga Maldonado1 years ago | 4 | using System.Diagnostics.CodeAnalysis; |
9f9f2936Jose Arriaga Maldonado2 years ago | 5 | using System.IO; |
19a65a0aKrzysztof Cwalina2 years ago | 6 | using System.Threading; |
9f9f2936Jose Arriaga Maldonado2 years ago | 7 | using System.Threading.Tasks; |
| 8 | | |
| 9 | namespace OpenAI.Files; | |
| 10 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 11 | // CUSTOM: |
| 12 | // - Renamed. | |
| 13 | // - Suppressed constructor that takes endpoint parameter; endpoint is now a property in the options class. | |
| 14 | /// <summary> The service client for OpenAI file operations. </summary> | |
0ca4c062Jose Arriaga Maldonado1 years ago | 15 | [CodeGenType("Files")] |
| 16 | [CodeGenSuppress("OpenAIFileClient", typeof(ClientPipeline), typeof(Uri))] | |
5dce104aJose Arriaga Maldonado1 years ago | 17 | [CodeGenSuppress("GetFilesAsync", typeof(string), typeof(CancellationToken))] |
| 18 | [CodeGenSuppress("GetFiles", typeof(string), typeof(CancellationToken))] | |
dff9bb58Jose Arriaga Maldonado1 years ago | 19 | [CodeGenSuppress("GetFileAsync", typeof(string), typeof(CancellationToken))] |
| 20 | [CodeGenSuppress("GetFile", typeof(string), typeof(CancellationToken))] | |
31c2ba63Jose Arriaga Maldonado1 years ago | 21 | public partial class OpenAIFileClient |
9f9f2936Jose Arriaga Maldonado2 years ago | 22 | { |
3467b535Travis Wilson1 years ago | 23 | private InternalUploadsClient _internalUploadsClient; |
| 24 | | |
2ab1a942Jose Arriaga Maldonado1 years ago | 25 | // CUSTOM: Added as a convenience. |
e0fee603Jose Arriaga Maldonado1 years ago | 26 | /// <summary> Initializes a new instance of <see cref="OpenAIFileClient"/>. </summary> |
2ab1a942Jose Arriaga Maldonado1 years ago | 27 | /// <param name="apiKey"> The API key to authenticate with the service. </param> |
e0fee603Jose Arriaga Maldonado1 years ago | 28 | /// <exception cref="ArgumentNullException"> <paramref name="apiKey"/> is null. </exception> |
31c2ba63Jose Arriaga Maldonado1 years ago | 29 | public OpenAIFileClient(string apiKey) : this(new ApiKeyCredential(apiKey), new OpenAIClientOptions()) |
2ab1a942Jose Arriaga Maldonado1 years ago | 30 | { |
| 31 | } | |
| 32 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 33 | // CUSTOM: |
| 34 | // - Used a custom pipeline. | |
| 35 | // - Demoted the endpoint parameter to be a property in the options class. | |
e0fee603Jose Arriaga Maldonado1 years ago | 36 | /// <summary> Initializes a new instance of <see cref="OpenAIFileClient"/>. </summary> |
13a9c686Jose Arriaga Maldonado1 years ago | 37 | /// <param name="credential"> The API key to authenticate with the service. </param> |
| 38 | /// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception> | |
31c2ba63Jose Arriaga Maldonado1 years ago | 39 | public OpenAIFileClient(ApiKeyCredential credential) : this(credential, new OpenAIClientOptions()) |
9f9f2936Jose Arriaga Maldonado2 years ago | 40 | { |
| 41 | } | |
| 42 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 43 | // CUSTOM: |
| 44 | // - Used a custom pipeline. | |
| 45 | // - Demoted the endpoint parameter to be a property in the options class. | |
e0fee603Jose Arriaga Maldonado1 years ago | 46 | /// <summary> Initializes a new instance of <see cref="OpenAIFileClient"/>. </summary> |
13a9c686Jose Arriaga Maldonado1 years ago | 47 | /// <param name="credential"> The API key to authenticate with the service. </param> |
| 48 | /// <param name="options"> The options to configure the client. </param> | |
| 49 | /// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception> | |
3613b6a0Jose Arriaga Maldonado1 years ago | 50 | public OpenAIFileClient(ApiKeyCredential credential, OpenAIClientOptions options) : this(OpenAIClient.CreateApiKeyAuthenticationPolicy(credential), options) |
9f9f2936Jose Arriaga Maldonado2 years ago | 51 | { |
3613b6a0Jose Arriaga Maldonado1 years ago | 52 | } |
| 53 | | |
| 54 | // CUSTOM: Added as a convenience. | |
| 55 | /// <summary> Initializes a new instance of <see cref="OpenAIFileClient"/>. </summary> | |
| 56 | /// <param name="authenticationPolicy"> The authentication policy used to authenticate with the service. </param> | |
| 57 | /// <exception cref="ArgumentNullException"> <paramref name="authenticationPolicy"/> is null. </exception> | |
| 58 | [Experimental("OPENAI001")] | |
| 59 | public OpenAIFileClient(AuthenticationPolicy authenticationPolicy) : this(authenticationPolicy, new OpenAIClientOptions()) | |
| 60 | { | |
| 61 | } | |
| 62 | | |
| 63 | // CUSTOM: Added as a convenience. | |
| 64 | /// <summary> Initializes a new instance of <see cref="OpenAIFileClient"/>. </summary> | |
| 65 | /// <param name="authenticationPolicy"> The authentication policy used to authenticate with the service. </param> | |
| 66 | /// <param name="options"> The options to configure the client. </param> | |
| 67 | /// <exception cref="ArgumentNullException"> <paramref name="authenticationPolicy"/> is null. </exception> | |
| 68 | [Experimental("OPENAI001")] | |
| 69 | public OpenAIFileClient(AuthenticationPolicy authenticationPolicy, OpenAIClientOptions options) | |
| 70 | { | |
| 71 | Argument.AssertNotNull(authenticationPolicy, nameof(authenticationPolicy)); | |
13a9c686Jose Arriaga Maldonado1 years ago | 72 | options ??= new OpenAIClientOptions(); |
| 73 | | |
3613b6a0Jose Arriaga Maldonado1 years ago | 74 | Pipeline = OpenAIClient.CreatePipeline(authenticationPolicy, options); |
13a9c686Jose Arriaga Maldonado1 years ago | 75 | _endpoint = OpenAIClient.GetEndpoint(options); |
e0fee603Jose Arriaga Maldonado1 years ago | 76 | _internalUploadsClient = new(Pipeline, options); |
9f9f2936Jose Arriaga Maldonado2 years ago | 77 | } |
| 78 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 79 | // CUSTOM: |
| 80 | // - Used a custom pipeline. | |
| 81 | // - Demoted the endpoint parameter to be a property in the options class. | |
| 82 | // - Made protected. | |
e0fee603Jose Arriaga Maldonado1 years ago | 83 | /// <summary> Initializes a new instance of <see cref="OpenAIFileClient"/>. </summary> |
13a9c686Jose Arriaga Maldonado1 years ago | 84 | /// <param name="pipeline"> The HTTP pipeline to send and receive REST requests and responses. </param> |
| 85 | /// <param name="options"> The options to configure the client. </param> | |
| 86 | /// <exception cref="ArgumentNullException"> <paramref name="pipeline"/> is null. </exception> | |
31c2ba63Jose Arriaga Maldonado1 years ago | 87 | protected internal OpenAIFileClient(ClientPipeline pipeline, OpenAIClientOptions options) |
9f9f2936Jose Arriaga Maldonado2 years ago | 88 | { |
13a9c686Jose Arriaga Maldonado1 years ago | 89 | Argument.AssertNotNull(pipeline, nameof(pipeline)); |
| 90 | options ??= new OpenAIClientOptions(); | |
| 91 | | |
e0fee603Jose Arriaga Maldonado1 years ago | 92 | Pipeline = pipeline; |
13a9c686Jose Arriaga Maldonado1 years ago | 93 | _endpoint = OpenAIClient.GetEndpoint(options); |
3467b535Travis Wilson1 years ago | 94 | _internalUploadsClient = new(pipeline, options); |
9f9f2936Jose Arriaga Maldonado2 years ago | 95 | } |
| 96 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 97 | /// <summary> Uploads a file that can be used across various operations. </summary> |
| 98 | /// <remarks> Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB. </remarks> | |
| 99 | /// <param name="file"> The file stream to upload. </param> | |
9f9f2936Jose Arriaga Maldonado2 years ago | 100 | /// <param name="filename"> |
13a9c686Jose Arriaga Maldonado1 years ago | 101 | /// The filename associated with the file stream. The filename's extension (for example: .json) will be used to |
| 102 | /// validate the file format. The request may fail if the filename's extension and the actual file format do | |
| 103 | /// not match. | |
9f9f2936Jose Arriaga Maldonado2 years ago | 104 | /// </param> |
| 105 | /// <param name="purpose"> The intended purpose of the uploaded file. </param> | |
13a9c686Jose Arriaga Maldonado1 years ago | 106 | /// <param name="cancellationToken"> A token that can be used to cancel this method call. </param> |
9f9f2936Jose Arriaga Maldonado2 years ago | 107 | /// <exception cref="ArgumentNullException"> <paramref name="file"/> or <paramref name="filename"/> is null. </exception> |
| 108 | /// <exception cref="ArgumentException"> <paramref name="filename"/> is an empty string, and was expected to be non-empty. </exception> | |
19ceae44ShivangiReja1 years ago | 109 | public virtual async Task<ClientResult<OpenAIFile>> UploadFileAsync(Stream file, string filename, FileUploadPurpose purpose, CancellationToken cancellationToken = default) |
9f9f2936Jose Arriaga Maldonado2 years ago | 110 | { |
| 111 | Argument.AssertNotNull(file, nameof(file)); | |
| 112 | Argument.AssertNotNullOrEmpty(filename, nameof(filename)); | |
| 113 | | |
| 114 | InternalFileUploadOptions options = new() | |
| 115 | { | |
| 116 | Purpose = purpose | |
| 117 | }; | |
| 118 | | |
0ca4c062Jose Arriaga Maldonado1 years ago | 119 | using MultiPartFormDataBinaryContent content = options.ToMultipartContent(file, filename); |
19a65a0aKrzysztof Cwalina2 years ago | 120 | ClientResult result = await UploadFileAsync(content, content.ContentType, cancellationToken.ToRequestOptions()).ConfigureAwait(false); |
5dce104aJose Arriaga Maldonado1 years ago | 121 | return ClientResult.FromValue(OpenAIFile.FromClientResult(result), result.GetRawResponse()); |
9f9f2936Jose Arriaga Maldonado2 years ago | 122 | } |
| 123 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 124 | /// <summary> Uploads a file that can be used across various operations. </summary> |
| 125 | /// <remarks> Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB. </remarks> | |
| 126 | /// <param name="file"> The file stream to upload. </param> | |
9f9f2936Jose Arriaga Maldonado2 years ago | 127 | /// <param name="filename"> |
13a9c686Jose Arriaga Maldonado1 years ago | 128 | /// The filename associated with the file stream. The filename's extension (for example: .json) will be used to |
| 129 | /// validate the file format. The request may fail if the filename's extension and the actual file format do | |
| 130 | /// not match. | |
9f9f2936Jose Arriaga Maldonado2 years ago | 131 | /// </param> |
| 132 | /// <param name="purpose"> The intended purpose of the uploaded file. </param> | |
13a9c686Jose Arriaga Maldonado1 years ago | 133 | /// <param name="cancellationToken"> A token that can be used to cancel this method call. </param> |
9f9f2936Jose Arriaga Maldonado2 years ago | 134 | /// <exception cref="ArgumentNullException"> <paramref name="file"/> or <paramref name="filename"/> is null. </exception> |
| 135 | /// <exception cref="ArgumentException"> <paramref name="filename"/> is an empty string, and was expected to be non-empty. </exception> | |
19ceae44ShivangiReja1 years ago | 136 | public virtual ClientResult<OpenAIFile> UploadFile(Stream file, string filename, FileUploadPurpose purpose, CancellationToken cancellationToken = default) |
9f9f2936Jose Arriaga Maldonado2 years ago | 137 | { |
| 138 | Argument.AssertNotNull(file, nameof(file)); | |
| 139 | Argument.AssertNotNullOrEmpty(filename, nameof(filename)); | |
| 140 | | |
| 141 | InternalFileUploadOptions options = new() | |
| 142 | { | |
| 143 | Purpose = purpose | |
| 144 | }; | |
| 145 | | |
0ca4c062Jose Arriaga Maldonado1 years ago | 146 | using MultiPartFormDataBinaryContent content = options.ToMultipartContent(file, filename); |
19a65a0aKrzysztof Cwalina2 years ago | 147 | ClientResult result = UploadFile(content, content.ContentType, cancellationToken.ToRequestOptions()); |
5dce104aJose Arriaga Maldonado1 years ago | 148 | return ClientResult.FromValue(OpenAIFile.FromClientResult(result), result.GetRawResponse()); |
9f9f2936Jose Arriaga Maldonado2 years ago | 149 | } |
| 150 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 151 | /// <summary> Uploads a file that can be used across various operations. </summary> |
| 152 | /// <remarks> Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB. </remarks> | |
| 153 | /// <param name="file"> The file bytes to upload. </param> | |
9f9f2936Jose Arriaga Maldonado2 years ago | 154 | /// <param name="filename"> |
13a9c686Jose Arriaga Maldonado1 years ago | 155 | /// The filename associated with the file bytes. The filename's extension (for example: .json) will be used to |
| 156 | /// validate the file format. The request may fail if the filename's extension and the actual file format do | |
| 157 | /// not match. | |
9f9f2936Jose Arriaga Maldonado2 years ago | 158 | /// </param> |
| 159 | /// <param name="purpose"> The intended purpose of the uploaded file. </param> | |
| 160 | /// <exception cref="ArgumentNullException"> <paramref name="file"/> or <paramref name="filename"/> is null. </exception> | |
| 161 | /// <exception cref="ArgumentException"> <paramref name="filename"/> is an empty string, and was expected to be non-empty. </exception> | |
19ceae44ShivangiReja1 years ago | 162 | public virtual Task<ClientResult<OpenAIFile>> UploadFileAsync(BinaryData file, string filename, FileUploadPurpose purpose) |
9f9f2936Jose Arriaga Maldonado2 years ago | 163 | { |
| 164 | Argument.AssertNotNull(file, nameof(file)); | |
| 165 | Argument.AssertNotNullOrEmpty(filename, nameof(filename)); | |
| 166 | | |
| 167 | return UploadFileAsync(file?.ToStream(), filename, purpose); | |
| 168 | } | |
| 169 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 170 | /// <summary> Uploads a file that can be used across various operations. </summary> |
| 171 | /// <remarks> Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB. </remarks> | |
| 172 | /// <param name="file"> The file bytes to upload. </param> | |
9f9f2936Jose Arriaga Maldonado2 years ago | 173 | /// <param name="filename"> |
13a9c686Jose Arriaga Maldonado1 years ago | 174 | /// The filename associated with the file bytes. The filename's extension (for example: .json) will be used to |
| 175 | /// validate the file format. The request may fail if the filename's extension and the actual file format do | |
| 176 | /// not match. | |
9f9f2936Jose Arriaga Maldonado2 years ago | 177 | /// </param> |
| 178 | /// <param name="purpose"> The intended purpose of the uploaded file. </param> | |
| 179 | /// <exception cref="ArgumentNullException"> <paramref name="file"/> or <paramref name="filename"/> is null. </exception> | |
| 180 | /// <exception cref="ArgumentException"> <paramref name="filename"/> is an empty string, and was expected to be non-empty. </exception> | |
19ceae44ShivangiReja1 years ago | 181 | public virtual ClientResult<OpenAIFile> UploadFile(BinaryData file, string filename, FileUploadPurpose purpose) |
9f9f2936Jose Arriaga Maldonado2 years ago | 182 | { |
| 183 | Argument.AssertNotNull(file, nameof(file)); | |
| 184 | Argument.AssertNotNullOrEmpty(filename, nameof(filename)); | |
| 185 | | |
| 186 | return UploadFile(file?.ToStream(), filename, purpose); | |
| 187 | } | |
| 188 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 189 | /// <summary> Uploads a file that can be used across various operations. </summary> |
| 190 | /// <remarks> Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB. </remarks> | |
9f9f2936Jose Arriaga Maldonado2 years ago | 191 | /// <param name="filePath"> |
13a9c686Jose Arriaga Maldonado1 years ago | 192 | /// The path of the file to upload. The provided file path's extension (for example: .json) will be used to |
| 193 | /// validate the file format. The request may fail if the file path's extension and the actual file format do | |
| 194 | /// not match. | |
9f9f2936Jose Arriaga Maldonado2 years ago | 195 | /// </param> |
| 196 | /// <param name="purpose"> The intended purpose of the uploaded file. </param> | |
| 197 | /// <exception cref="ArgumentNullException"> <paramref name="filePath"/> was null. </exception> | |
| 198 | /// <exception cref="ArgumentException"> <paramref name="filePath"/> is an empty string, and was expected to be non-empty. </exception> | |
19ceae44ShivangiReja1 years ago | 199 | public virtual async Task<ClientResult<OpenAIFile>> UploadFileAsync(string filePath, FileUploadPurpose purpose) |
9f9f2936Jose Arriaga Maldonado2 years ago | 200 | { |
| 201 | Argument.AssertNotNullOrEmpty(filePath, nameof(filePath)); | |
| 202 | | |
| 203 | using FileStream stream = File.OpenRead(filePath); | |
| 204 | return await UploadFileAsync(stream, filePath, purpose).ConfigureAwait(false); | |
| 205 | } | |
| 206 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 207 | /// <summary> Uploads a file that can be used across various operations. </summary> |
| 208 | /// <remarks> Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB. </remarks> | |
9f9f2936Jose Arriaga Maldonado2 years ago | 209 | /// <param name="filePath"> |
13a9c686Jose Arriaga Maldonado1 years ago | 210 | /// The path of the file to upload. The provided file path's extension (for example: .json) will be used to |
| 211 | /// validate the file format. The request may fail if the file path's extension and the actual file format do | |
| 212 | /// not match. | |
9f9f2936Jose Arriaga Maldonado2 years ago | 213 | /// </param> |
| 214 | /// <param name="purpose"> The intended purpose of the uploaded file. </param> | |
| 215 | /// <exception cref="ArgumentNullException"> <paramref name="filePath"/> was null. </exception> | |
| 216 | /// <exception cref="ArgumentException"> <paramref name="filePath"/> is an empty string, and was expected to be non-empty. </exception> | |
19ceae44ShivangiReja1 years ago | 217 | public virtual ClientResult<OpenAIFile> UploadFile(string filePath, FileUploadPurpose purpose) |
9f9f2936Jose Arriaga Maldonado2 years ago | 218 | { |
| 219 | Argument.AssertNotNullOrEmpty(filePath, nameof(filePath)); | |
| 220 | | |
| 221 | using FileStream stream = File.OpenRead(filePath); | |
| 222 | return UploadFile(stream, filePath, purpose); | |
| 223 | } | |
| 224 | | |
2ab1a942Jose Arriaga Maldonado1 years ago | 225 | /// <summary> Gets basic information about each of the files belonging to the user's organization. </summary> |
| 226 | /// <param name="cancellationToken"> A token that can be used to cancel this method call. </param> | |
19ceae44ShivangiReja1 years ago | 227 | public virtual async Task<ClientResult<OpenAIFileCollection>> GetFilesAsync(CancellationToken cancellationToken = default) |
2ab1a942Jose Arriaga Maldonado1 years ago | 228 | { |
| 229 | ClientResult result = await GetFilesAsync(null, cancellationToken.ToRequestOptions()).ConfigureAwait(false); | |
5dce104aJose Arriaga Maldonado1 years ago | 230 | return ClientResult.FromValue(OpenAIFileCollection.FromClientResult(result), result.GetRawResponse()); |
2ab1a942Jose Arriaga Maldonado1 years ago | 231 | } |
| 232 | | |
| 233 | /// <summary> Gets basic information about each of the files belonging to the user's organization. </summary> | |
| 234 | /// <param name="cancellationToken"> A token that can be used to cancel this method call. </param> | |
19ceae44ShivangiReja1 years ago | 235 | public virtual ClientResult<OpenAIFileCollection> GetFiles(CancellationToken cancellationToken = default) |
2ab1a942Jose Arriaga Maldonado1 years ago | 236 | { |
| 237 | ClientResult result = GetFiles(null, cancellationToken.ToRequestOptions()); | |
5dce104aJose Arriaga Maldonado1 years ago | 238 | return ClientResult.FromValue(OpenAIFileCollection.FromClientResult(result), result.GetRawResponse()); |
2ab1a942Jose Arriaga Maldonado1 years ago | 239 | } |
| 240 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 241 | /// <summary> Gets basic information about each of the files belonging to the user's organization. </summary> |
9f9f2936Jose Arriaga Maldonado2 years ago | 242 | /// <param name="purpose"> Only return files with the given purpose. </param> |
13a9c686Jose Arriaga Maldonado1 years ago | 243 | /// <param name="cancellationToken"> A token that can be used to cancel this method call. </param> |
a330c2e7Jose Arriaga Maldonado1 years ago | 244 | public virtual async Task<ClientResult<OpenAIFileCollection>> GetFilesAsync(FilePurpose purpose, CancellationToken cancellationToken = default) |
9f9f2936Jose Arriaga Maldonado2 years ago | 245 | { |
a330c2e7Jose Arriaga Maldonado1 years ago | 246 | ClientResult result = await GetFilesAsync(purpose.ToSerialString(), cancellationToken.ToRequestOptions()).ConfigureAwait(false); |
5dce104aJose Arriaga Maldonado1 years ago | 247 | return ClientResult.FromValue(OpenAIFileCollection.FromClientResult(result), result.GetRawResponse()); |
9f9f2936Jose Arriaga Maldonado2 years ago | 248 | } |
| 249 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 250 | /// <summary> Gets basic information about each of the files belonging to the user's organization. </summary> |
9f9f2936Jose Arriaga Maldonado2 years ago | 251 | /// <param name="purpose"> Only return files with the given purpose. </param> |
13a9c686Jose Arriaga Maldonado1 years ago | 252 | /// <param name="cancellationToken"> A token that can be used to cancel this method call. </param> |
a330c2e7Jose Arriaga Maldonado1 years ago | 253 | public virtual ClientResult<OpenAIFileCollection> GetFiles(FilePurpose purpose, CancellationToken cancellationToken = default) |
9f9f2936Jose Arriaga Maldonado2 years ago | 254 | { |
a330c2e7Jose Arriaga Maldonado1 years ago | 255 | ClientResult result = GetFiles(purpose.ToSerialString(), cancellationToken.ToRequestOptions()); |
5dce104aJose Arriaga Maldonado1 years ago | 256 | return ClientResult.FromValue(OpenAIFileCollection.FromClientResult(result), result.GetRawResponse()); |
9f9f2936Jose Arriaga Maldonado2 years ago | 257 | } |
| 258 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 259 | /// <summary> Gets basic information about the specified file. </summary> |
| 260 | /// <param name="fileId"> The ID of the desired file. </param> | |
| 261 | /// <param name="cancellationToken"> A token that can be used to cancel this method call. </param> | |
9f9f2936Jose Arriaga Maldonado2 years ago | 262 | /// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception> |
| 263 | /// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception> | |
19ceae44ShivangiReja1 years ago | 264 | public virtual async Task<ClientResult<OpenAIFile>> GetFileAsync(string fileId, CancellationToken cancellationToken = default) |
9f9f2936Jose Arriaga Maldonado2 years ago | 265 | { |
| 266 | Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); | |
| 267 | | |
19a65a0aKrzysztof Cwalina2 years ago | 268 | ClientResult result = await GetFileAsync(fileId, cancellationToken.ToRequestOptions()).ConfigureAwait(false); |
5dce104aJose Arriaga Maldonado1 years ago | 269 | return ClientResult.FromValue(OpenAIFile.FromClientResult(result), result.GetRawResponse()); |
9f9f2936Jose Arriaga Maldonado2 years ago | 270 | } |
| 271 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 272 | /// <summary> Gets basic information about the specified file. </summary> |
| 273 | /// <param name="fileId"> The ID of the desired file. </param> | |
| 274 | /// <param name="cancellationToken"> A token that can be used to cancel this method call. </param> | |
9f9f2936Jose Arriaga Maldonado2 years ago | 275 | /// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception> |
| 276 | /// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception> | |
19ceae44ShivangiReja1 years ago | 277 | public virtual ClientResult<OpenAIFile> GetFile(string fileId, CancellationToken cancellationToken = default) |
9f9f2936Jose Arriaga Maldonado2 years ago | 278 | { |
| 279 | Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); | |
| 280 | | |
19a65a0aKrzysztof Cwalina2 years ago | 281 | ClientResult result = GetFile(fileId, cancellationToken.ToRequestOptions()); |
5dce104aJose Arriaga Maldonado1 years ago | 282 | return ClientResult.FromValue(OpenAIFile.FromClientResult(result), result.GetRawResponse()); |
9f9f2936Jose Arriaga Maldonado2 years ago | 283 | } |
| 284 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 285 | /// <summary> Deletes the specified file. </summary> |
9f9f2936Jose Arriaga Maldonado2 years ago | 286 | /// <param name="fileId"> The ID of the file to delete. </param> |
13a9c686Jose Arriaga Maldonado1 years ago | 287 | /// <param name="cancellationToken"> A token that can be used to cancel this method call. </param> |
9f9f2936Jose Arriaga Maldonado2 years ago | 288 | /// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception> |
| 289 | /// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception> | |
2ab1a942Jose Arriaga Maldonado1 years ago | 290 | public virtual async Task<ClientResult<FileDeletionResult>> DeleteFileAsync(string fileId, CancellationToken cancellationToken = default) |
9f9f2936Jose Arriaga Maldonado2 years ago | 291 | { |
| 292 | Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); | |
| 293 | | |
19a65a0aKrzysztof Cwalina2 years ago | 294 | ClientResult result = await DeleteFileAsync(fileId, cancellationToken.ToRequestOptions()).ConfigureAwait(false); |
5dce104aJose Arriaga Maldonado1 years ago | 295 | return ClientResult.FromValue(FileDeletionResult.FromClientResult(result), result.GetRawResponse()); |
9f9f2936Jose Arriaga Maldonado2 years ago | 296 | } |
| 297 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 298 | /// <summary> Deletes the specified file. </summary> |
9f9f2936Jose Arriaga Maldonado2 years ago | 299 | /// <param name="fileId"> The ID of the file to delete. </param> |
13a9c686Jose Arriaga Maldonado1 years ago | 300 | /// <param name="cancellationToken"> A token that can be used to cancel this method call. </param> |
9f9f2936Jose Arriaga Maldonado2 years ago | 301 | /// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception> |
| 302 | /// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception> | |
2ab1a942Jose Arriaga Maldonado1 years ago | 303 | public virtual ClientResult<FileDeletionResult> DeleteFile(string fileId, CancellationToken cancellationToken = default) |
9f9f2936Jose Arriaga Maldonado2 years ago | 304 | { |
| 305 | Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); | |
| 306 | | |
19a65a0aKrzysztof Cwalina2 years ago | 307 | ClientResult result = DeleteFile(fileId, cancellationToken.ToRequestOptions()); |
5dce104aJose Arriaga Maldonado1 years ago | 308 | return ClientResult.FromValue(FileDeletionResult.FromClientResult(result), result.GetRawResponse()); |
9f9f2936Jose Arriaga Maldonado2 years ago | 309 | } |
| 310 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 311 | /// <summary> Downloads the content of the specified file. </summary> |
9f9f2936Jose Arriaga Maldonado2 years ago | 312 | /// <param name="fileId"> The ID of the file to download. </param> |
13a9c686Jose Arriaga Maldonado1 years ago | 313 | /// <param name="cancellationToken"> A token that can be used to cancel this method call. </param> |
9f9f2936Jose Arriaga Maldonado2 years ago | 314 | /// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception> |
| 315 | /// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception> | |
19a65a0aKrzysztof Cwalina2 years ago | 316 | public virtual async Task<ClientResult<BinaryData>> DownloadFileAsync(string fileId, CancellationToken cancellationToken = default) |
9f9f2936Jose Arriaga Maldonado2 years ago | 317 | { |
| 318 | Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); | |
| 319 | | |
19a65a0aKrzysztof Cwalina2 years ago | 320 | ClientResult result = await DownloadFileAsync(fileId, cancellationToken.ToRequestOptions()).ConfigureAwait(false); |
9f9f2936Jose Arriaga Maldonado2 years ago | 321 | return ClientResult.FromValue(result.GetRawResponse().Content, result.GetRawResponse()); |
| 322 | } | |
| 323 | | |
13a9c686Jose Arriaga Maldonado1 years ago | 324 | /// <summary> Downloads the content of the specified file. </summary> |
9f9f2936Jose Arriaga Maldonado2 years ago | 325 | /// <param name="fileId"> The ID of the file to download. </param> |
13a9c686Jose Arriaga Maldonado1 years ago | 326 | /// <param name="cancellationToken"> A token that can be used to cancel this method call. </param> |
9f9f2936Jose Arriaga Maldonado2 years ago | 327 | /// <exception cref="ArgumentNullException"> <paramref name="fileId"/> is null. </exception> |
| 328 | /// <exception cref="ArgumentException"> <paramref name="fileId"/> is an empty string, and was expected to be non-empty. </exception> | |
19a65a0aKrzysztof Cwalina2 years ago | 329 | public virtual ClientResult<BinaryData> DownloadFile(string fileId, CancellationToken cancellationToken = default) |
9f9f2936Jose Arriaga Maldonado2 years ago | 330 | { |
| 331 | Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); | |
| 332 | | |
19a65a0aKrzysztof Cwalina2 years ago | 333 | ClientResult result = DownloadFile(fileId, cancellationToken.ToRequestOptions()); |
9f9f2936Jose Arriaga Maldonado2 years ago | 334 | return ClientResult.FromValue(result.GetRawResponse().Content, result.GetRawResponse()); |
| 335 | } | |
| 336 | } |