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