openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Files/FileClient.Protocol.cs
212lines · modecode
| 1 | using System; |
| 2 | using System.ClientModel; |
| 3 | using System.ClientModel.Primitives; |
| 4 | using System.ComponentModel; |
| 5 | using System.Threading.Tasks; |
| 6 | |
| 7 | namespace 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))] |
| 19 | public 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)] |
| 40 | public virtual async Task<ClientResult> UploadFileAsync(BinaryContent content, string contentType, RequestOptions options = null) |
| 41 | { |
| 42 | Argument.AssertNotNull(content, nameof(content)); |
| 43 | Argument.AssertNotNullOrEmpty(contentType, nameof(contentType)); |
| 44 | |
| 45 | using PipelineMessage message = CreateCreateFileRequest(content, contentType, options); |
| 46 | return 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)] |
| 68 | public virtual ClientResult UploadFile(BinaryContent content, string contentType, RequestOptions options = null) |
| 69 | { |
| 70 | Argument.AssertNotNull(content, nameof(content)); |
| 71 | Argument.AssertNotNullOrEmpty(contentType, nameof(contentType)); |
| 72 | |
| 73 | using PipelineMessage message = CreateCreateFileRequest(content, contentType, options); |
| 74 | return 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)] |
| 85 | public virtual async Task<ClientResult> GetFilesAsync(string purpose, RequestOptions options) |
| 86 | { |
| 87 | using PipelineMessage message = CreateGetFilesRequest(purpose, options); |
| 88 | return 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)] |
| 99 | public virtual ClientResult GetFiles(string purpose, RequestOptions options) |
| 100 | { |
| 101 | using PipelineMessage message = CreateGetFilesRequest(purpose, options); |
| 102 | return 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)] |
| 115 | public virtual async Task<ClientResult> GetFileAsync(string fileId, RequestOptions options) |
| 116 | { |
| 117 | Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); |
| 118 | |
| 119 | using PipelineMessage message = CreateRetrieveFileRequest(fileId, options); |
| 120 | return 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)] |
| 133 | public virtual ClientResult GetFile(string fileId, RequestOptions options) |
| 134 | { |
| 135 | Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); |
| 136 | |
| 137 | using PipelineMessage message = CreateRetrieveFileRequest(fileId, options); |
| 138 | return 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)] |
| 151 | public virtual async Task<ClientResult> DeleteFileAsync(string fileId, RequestOptions options) |
| 152 | { |
| 153 | Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); |
| 154 | |
| 155 | using PipelineMessage message = CreateDeleteFileRequest(fileId, options); |
| 156 | return 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)] |
| 169 | public virtual ClientResult DeleteFile(string fileId, RequestOptions options) |
| 170 | { |
| 171 | Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); |
| 172 | |
| 173 | using PipelineMessage message = CreateDeleteFileRequest(fileId, options); |
| 174 | return 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)] |
| 187 | public virtual async Task<ClientResult> DownloadFileAsync(string fileId, RequestOptions options) |
| 188 | { |
| 189 | Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); |
| 190 | |
| 191 | using PipelineMessage message = CreateDownloadFileRequest(fileId, options); |
| 192 | return 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)] |
| 205 | public virtual ClientResult DownloadFile(string fileId, RequestOptions options) |
| 206 | { |
| 207 | Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); |
| 208 | |
| 209 | using PipelineMessage message = CreateDownloadFileRequest(fileId, options); |
| 210 | return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); |
| 211 | } |
| 212 | } |
| 213 | |