openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.2.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Custom/Assistants/Internal/InternalAssistantRunClient.Protocol.cs

398lines · modecode

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