openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Assistants/Internal/InternalAssistantRunClient.Protocol.cs
351lines · modecode
| 1 | using System; |
| 2 | using System.ClientModel; |
| 3 | using System.ClientModel.Primitives; |
| 4 | using System.Threading.Tasks; |
| 5 | |
| 6 | namespace OpenAI.Assistants; |
| 7 | |
| 8 | internal partial class InternalAssistantRunClient |
| 9 | { |
| 10 | /// <summary> |
| 11 | /// [Protocol Method] Create a thread and run it in one request. |
| 12 | /// </summary> |
| 13 | /// <param name="content"> The content to send as the body of the request. </param> |
| 14 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 15 | /// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception> |
| 16 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 17 | /// <returns> The response returned from the service. </returns> |
| 18 | public virtual async Task<ClientResult> CreateThreadAndRunAsync(BinaryContent content, RequestOptions options = null) |
| 19 | { |
| 20 | Argument.AssertNotNull(content, nameof(content)); |
| 21 | |
| 22 | PipelineMessage message = null; |
| 23 | try |
| 24 | { |
| 25 | message = CreateCreateThreadAndRunRequest(content, options); |
| 26 | return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 27 | } |
| 28 | finally |
| 29 | { |
| 30 | if (options?.BufferResponse != false) |
| 31 | { |
| 32 | message.Dispose(); |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /// <summary> |
| 38 | /// [Protocol Method] Create a thread and run it in one request. |
| 39 | /// </summary> |
| 40 | /// <param name="content"> The content to send as the body of the request. </param> |
| 41 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 42 | /// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception> |
| 43 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 44 | /// <returns> The response returned from the service. </returns> |
| 45 | public virtual ClientResult CreateThreadAndRun(BinaryContent content, RequestOptions options = null) |
| 46 | { |
| 47 | Argument.AssertNotNull(content, nameof(content)); |
| 48 | |
| 49 | PipelineMessage message = null; |
| 50 | try |
| 51 | { |
| 52 | message = CreateCreateThreadAndRunRequest(content, options); |
| 53 | return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); |
| 54 | } |
| 55 | finally |
| 56 | { |
| 57 | if (options?.BufferResponse != false) |
| 58 | { |
| 59 | message.Dispose(); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /// <summary> |
| 65 | /// [Protocol Method] Create a run. |
| 66 | /// </summary> |
| 67 | /// <param name="threadId"> The ID of the thread to run. </param> |
| 68 | /// <param name="content"> The content to send as the body of the request. </param> |
| 69 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 70 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="content"/> is null. </exception> |
| 71 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> is an empty string, and was expected to be non-empty. </exception> |
| 72 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 73 | /// <returns> The response returned from the service. </returns> |
| 74 | public virtual async Task<ClientResult> CreateRunAsync(string threadId, BinaryContent content, RequestOptions options = null) |
| 75 | { |
| 76 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 77 | Argument.AssertNotNull(content, nameof(content)); |
| 78 | |
| 79 | PipelineMessage message = null; |
| 80 | try |
| 81 | { |
| 82 | message = CreateCreateRunRequest(threadId, content, options); |
| 83 | return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 84 | } |
| 85 | finally |
| 86 | { |
| 87 | if (options?.BufferResponse != false) |
| 88 | { |
| 89 | message.Dispose(); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /// <summary> |
| 95 | /// [Protocol Method] Create a run. |
| 96 | /// </summary> |
| 97 | /// <param name="threadId"> The ID of the thread to run. </param> |
| 98 | /// <param name="content"> The content to send as the body of the request. </param> |
| 99 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 100 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="content"/> is null. </exception> |
| 101 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> is an empty string, and was expected to be non-empty. </exception> |
| 102 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 103 | /// <returns> The response returned from the service. </returns> |
| 104 | public virtual ClientResult CreateRun(string threadId, BinaryContent content, RequestOptions options = null) |
| 105 | { |
| 106 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 107 | Argument.AssertNotNull(content, nameof(content)); |
| 108 | |
| 109 | PipelineMessage message = null; |
| 110 | try |
| 111 | { |
| 112 | message = CreateCreateRunRequest(threadId, content, options); |
| 113 | return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); |
| 114 | } |
| 115 | finally |
| 116 | { |
| 117 | if (options?.BufferResponse != false) |
| 118 | { |
| 119 | message.Dispose(); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /// <summary> |
| 125 | /// [Protocol Method] Retrieves a run. |
| 126 | /// </summary> |
| 127 | /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) that was run. </param> |
| 128 | /// <param name="runId"> The ID of the run to retrieve. </param> |
| 129 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 130 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="runId"/> is null. </exception> |
| 131 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="runId"/> is an empty string, and was expected to be non-empty. </exception> |
| 132 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 133 | /// <returns> The response returned from the service. </returns> |
| 134 | public virtual async Task<ClientResult> GetRunAsync(string threadId, string runId, RequestOptions options) |
| 135 | { |
| 136 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 137 | Argument.AssertNotNullOrEmpty(runId, nameof(runId)); |
| 138 | |
| 139 | using PipelineMessage message = CreateGetRunRequest(threadId, runId, options); |
| 140 | return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 141 | } |
| 142 | |
| 143 | /// <summary> |
| 144 | /// [Protocol Method] Retrieves a run. |
| 145 | /// </summary> |
| 146 | /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) that was run. </param> |
| 147 | /// <param name="runId"> The ID of the run to retrieve. </param> |
| 148 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 149 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="runId"/> is null. </exception> |
| 150 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="runId"/> is an empty string, and was expected to be non-empty. </exception> |
| 151 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 152 | /// <returns> The response returned from the service. </returns> |
| 153 | public virtual ClientResult GetRun(string threadId, string runId, RequestOptions options) |
| 154 | { |
| 155 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 156 | Argument.AssertNotNullOrEmpty(runId, nameof(runId)); |
| 157 | |
| 158 | using PipelineMessage message = CreateGetRunRequest(threadId, runId, options); |
| 159 | return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); |
| 160 | } |
| 161 | |
| 162 | /// <summary> |
| 163 | /// [Protocol Method] Modifies a run. |
| 164 | /// </summary> |
| 165 | /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) that was run. </param> |
| 166 | /// <param name="runId"> The ID of the run to modify. </param> |
| 167 | /// <param name="content"> The content to send as the body of the request. </param> |
| 168 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 169 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/>, <paramref name="runId"/> or <paramref name="content"/> is null. </exception> |
| 170 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="runId"/> is an empty string, and was expected to be non-empty. </exception> |
| 171 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 172 | /// <returns> The response returned from the service. </returns> |
| 173 | public virtual async Task<ClientResult> ModifyRunAsync(string threadId, string runId, BinaryContent content, RequestOptions options = null) |
| 174 | { |
| 175 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 176 | Argument.AssertNotNullOrEmpty(runId, nameof(runId)); |
| 177 | Argument.AssertNotNull(content, nameof(content)); |
| 178 | |
| 179 | using PipelineMessage message = CreateModifyRunRequest(threadId, runId, content, options); |
| 180 | return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 181 | } |
| 182 | |
| 183 | /// <summary> |
| 184 | /// [Protocol Method] Modifies a run. |
| 185 | /// </summary> |
| 186 | /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) that was run. </param> |
| 187 | /// <param name="runId"> The ID of the run to modify. </param> |
| 188 | /// <param name="content"> The content to send as the body of the request. </param> |
| 189 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 190 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/>, <paramref name="runId"/> or <paramref name="content"/> is null. </exception> |
| 191 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="runId"/> is an empty string, and was expected to be non-empty. </exception> |
| 192 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 193 | /// <returns> The response returned from the service. </returns> |
| 194 | public virtual ClientResult ModifyRun(string threadId, string runId, BinaryContent content, RequestOptions options = null) |
| 195 | { |
| 196 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 197 | Argument.AssertNotNullOrEmpty(runId, nameof(runId)); |
| 198 | Argument.AssertNotNull(content, nameof(content)); |
| 199 | |
| 200 | using PipelineMessage message = CreateModifyRunRequest(threadId, runId, content, options); |
| 201 | return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); |
| 202 | } |
| 203 | |
| 204 | /// <summary> |
| 205 | /// [Protocol Method] Cancels a run that is `in_progress`. |
| 206 | /// </summary> |
| 207 | /// <param name="threadId"> The ID of the thread to which this run belongs. </param> |
| 208 | /// <param name="runId"> The ID of the run to cancel. </param> |
| 209 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 210 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="runId"/> is null. </exception> |
| 211 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="runId"/> is an empty string, and was expected to be non-empty. </exception> |
| 212 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 213 | /// <returns> The response returned from the service. </returns> |
| 214 | public virtual async Task<ClientResult> CancelRunAsync(string threadId, string runId, RequestOptions options) |
| 215 | { |
| 216 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 217 | Argument.AssertNotNullOrEmpty(runId, nameof(runId)); |
| 218 | |
| 219 | using PipelineMessage message = CreateCancelRunRequest(threadId, runId, options); |
| 220 | return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 221 | } |
| 222 | |
| 223 | /// <summary> |
| 224 | /// [Protocol Method] Cancels a run that is `in_progress`. |
| 225 | /// </summary> |
| 226 | /// <param name="threadId"> The ID of the thread to which this run belongs. </param> |
| 227 | /// <param name="runId"> The ID of the run to cancel. </param> |
| 228 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 229 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="runId"/> is null. </exception> |
| 230 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="runId"/> is an empty string, and was expected to be non-empty. </exception> |
| 231 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 232 | /// <returns> The response returned from the service. </returns> |
| 233 | public virtual ClientResult CancelRun(string threadId, string runId, RequestOptions options) |
| 234 | { |
| 235 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 236 | Argument.AssertNotNullOrEmpty(runId, nameof(runId)); |
| 237 | |
| 238 | using PipelineMessage message = CreateCancelRunRequest(threadId, runId, options); |
| 239 | return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); |
| 240 | } |
| 241 | |
| 242 | /// <summary> |
| 243 | /// [Protocol Method] When a run has the `status: "requires_action"` and `required_action.type` is |
| 244 | /// `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once |
| 245 | /// they're all completed. All outputs must be submitted in a single request. |
| 246 | /// </summary> |
| 247 | /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) to which this run belongs. </param> |
| 248 | /// <param name="runId"> The ID of the run that requires the tool output submission. </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> |
| 251 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/>, <paramref name="runId"/> or <paramref name="content"/> is null. </exception> |
| 252 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="runId"/> 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 | public virtual async Task<ClientResult> SubmitToolOutputsToRunAsync(string threadId, string runId, BinaryContent content, RequestOptions options = null) |
| 256 | { |
| 257 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 258 | Argument.AssertNotNullOrEmpty(runId, nameof(runId)); |
| 259 | Argument.AssertNotNull(content, nameof(content)); |
| 260 | |
| 261 | PipelineMessage message = null; |
| 262 | try |
| 263 | { |
| 264 | message = CreateSubmitToolOutputsToRunRequest(threadId, runId, content, options); |
| 265 | return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 266 | } |
| 267 | finally |
| 268 | { |
| 269 | if (options?.BufferResponse != false) |
| 270 | { |
| 271 | message.Dispose(); |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | /// <summary> |
| 277 | /// [Protocol Method] When a run has the `status: "requires_action"` and `required_action.type` is |
| 278 | /// `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once |
| 279 | /// they're all completed. All outputs must be submitted in a single request. |
| 280 | /// </summary> |
| 281 | /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) to which this run belongs. </param> |
| 282 | /// <param name="runId"> The ID of the run that requires the tool output submission. </param> |
| 283 | /// <param name="content"> The content to send as the body of the request. </param> |
| 284 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 285 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/>, <paramref name="runId"/> or <paramref name="content"/> is null. </exception> |
| 286 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="runId"/> is an empty string, and was expected to be non-empty. </exception> |
| 287 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 288 | /// <returns> The response returned from the service. </returns> |
| 289 | public virtual ClientResult SubmitToolOutputsToRun(string threadId, string runId, BinaryContent content, RequestOptions options = null) |
| 290 | { |
| 291 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 292 | Argument.AssertNotNullOrEmpty(runId, nameof(runId)); |
| 293 | Argument.AssertNotNull(content, nameof(content)); |
| 294 | |
| 295 | PipelineMessage message = null; |
| 296 | try |
| 297 | { |
| 298 | message = CreateSubmitToolOutputsToRunRequest(threadId, runId, content, options); |
| 299 | return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); |
| 300 | } |
| 301 | finally |
| 302 | { |
| 303 | if (options?.BufferResponse != false) |
| 304 | { |
| 305 | message.Dispose(); |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /// <summary> |
| 311 | /// [Protocol Method] Retrieves a run step. |
| 312 | /// </summary> |
| 313 | /// <param name="threadId"> The ID of the thread to which the run and run step belongs. </param> |
| 314 | /// <param name="runId"> The ID of the run to which the run step belongs. </param> |
| 315 | /// <param name="stepId"> The ID of the run step to retrieve. </param> |
| 316 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 317 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/>, <paramref name="runId"/> or <paramref name="stepId"/> is null. </exception> |
| 318 | /// <exception cref="ArgumentException"> <paramref name="threadId"/>, <paramref name="runId"/> or <paramref name="stepId"/> is an empty string, and was expected to be non-empty. </exception> |
| 319 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 320 | /// <returns> The response returned from the service. </returns> |
| 321 | public virtual async Task<ClientResult> GetRunStepAsync(string threadId, string runId, string stepId, RequestOptions options) |
| 322 | { |
| 323 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 324 | Argument.AssertNotNullOrEmpty(runId, nameof(runId)); |
| 325 | Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); |
| 326 | |
| 327 | using PipelineMessage message = CreateGetRunStepRequest(threadId, runId, stepId, options); |
| 328 | return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 329 | } |
| 330 | |
| 331 | /// <summary> |
| 332 | /// [Protocol Method] Retrieves a run step. |
| 333 | /// </summary> |
| 334 | /// <param name="threadId"> The ID of the thread to which the run and run step belongs. </param> |
| 335 | /// <param name="runId"> The ID of the run to which the run step belongs. </param> |
| 336 | /// <param name="stepId"> The ID of the run step to retrieve. </param> |
| 337 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 338 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/>, <paramref name="runId"/> or <paramref name="stepId"/> is null. </exception> |
| 339 | /// <exception cref="ArgumentException"> <paramref name="threadId"/>, <paramref name="runId"/> or <paramref name="stepId"/> is an empty string, and was expected to be non-empty. </exception> |
| 340 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 341 | /// <returns> The response returned from the service. </returns> |
| 342 | public virtual ClientResult GetRunStep(string threadId, string runId, string stepId, RequestOptions options) |
| 343 | { |
| 344 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 345 | Argument.AssertNotNullOrEmpty(runId, nameof(runId)); |
| 346 | Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); |
| 347 | |
| 348 | using PipelineMessage message = CreateGetRunStepRequest(threadId, runId, stepId, options); |
| 349 | return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); |
| 350 | } |
| 351 | } |