openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
mailinhphan/clientOptions

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

285lines · modecode

1using Microsoft.TypeSpec.Generator.Customizations;
2using System;
3using System.ClientModel;
4using System.ClientModel.Primitives;
5using System.Collections.Generic;
6using System.Threading.Tasks;
7
8namespace OpenAI.Assistants;
9
10[CodeGenSuppress("CreateRunAsync", typeof(string), typeof(BinaryContent), typeof(IEnumerable<InternalIncludedRunStepProperty>), typeof(RequestOptions))]
11[CodeGenSuppress("CreateRun", typeof(string), typeof(BinaryContent), typeof(IEnumerable<InternalIncludedRunStepProperty>), typeof(RequestOptions))]
12[CodeGenSuppress("CreateThreadAndRunAsync", typeof(string), typeof(BinaryContent), typeof(RequestOptions))]
13[CodeGenSuppress("CreateThreadAndRun", typeof(string), typeof(BinaryContent), typeof(RequestOptions))]
14[CodeGenSuppress("SubmitToolOutputsToRunAsync", typeof(string), typeof(string), typeof(string), typeof(BinaryContent),typeof(RequestOptions))]
15[CodeGenSuppress("SubmitToolOutputsToRun", typeof(string), typeof(string), typeof(string), typeof(BinaryContent), typeof(RequestOptions))]
16internal partial class InternalAssistantRunClient
17{
18 /// <summary>
19 /// [Protocol Method] Create a thread and run it in one request.
20 /// </summary>
21 /// <param name="content"> The content to send as the body of the request. </param>
22 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
23 /// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception>
24 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
25 /// <returns> The response returned from the service. </returns>
26 public virtual async Task<ClientResult> CreateThreadAndRunAsync(BinaryContent content, RequestOptions options = null)
27 {
28 Argument.AssertNotNull(content, nameof(content));
29
30 PipelineMessage message = null;
31 try
32 {
33 message = CreateCreateThreadAndRunRequest(content, options);
34 return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
35 }
36 finally
37 {
38 if (options?.BufferResponse != false)
39 {
40 message.Dispose();
41 }
42 }
43 }
44
45 /// <summary>
46 /// [Protocol Method] Create a thread and run it in one request.
47 /// </summary>
48 /// <param name="content"> The content to send as the body of the request. </param>
49 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
50 /// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception>
51 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
52 /// <returns> The response returned from the service. </returns>
53 public virtual ClientResult CreateThreadAndRun(BinaryContent content, RequestOptions options = null)
54 {
55 Argument.AssertNotNull(content, nameof(content));
56
57 PipelineMessage message = null;
58 try
59 {
60 message = CreateCreateThreadAndRunRequest(content, options);
61 return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
62 }
63 finally
64 {
65 if (options?.BufferResponse != false)
66 {
67 message.Dispose();
68 }
69 }
70 }
71
72 /// <summary>
73 /// [Protocol Method] Create a run.
74 /// </summary>
75 /// <param name="threadId"> The ID of the thread to run. </param>
76 /// <param name="content"> The content to send as the body of the request. </param>
77 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
78 /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="content"/> is null. </exception>
79 /// <exception cref="ArgumentException"> <paramref name="threadId"/> is an empty string, and was expected to be non-empty. </exception>
80 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
81 /// <returns> The response returned from the service. </returns>
82 public virtual async Task<ClientResult> CreateRunAsync(string threadId, BinaryContent content, RequestOptions options = null)
83 {
84 Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
85 Argument.AssertNotNull(content, nameof(content));
86
87 PipelineMessage message = null;
88 try
89 {
90 // Always request the included properties.
91 IEnumerable<InternalIncludedRunStepProperty> includedRunStepProperties = [InternalIncludedRunStepProperty.FileSearchResultContent];
92
93 message = CreateCreateRunRequest(threadId, content, includedRunStepProperties, options);
94 return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
95 }
96 finally
97 {
98 if (options?.BufferResponse != false)
99 {
100 message.Dispose();
101 }
102 }
103 }
104
105 /// <summary>
106 /// [Protocol Method] Create a run.
107 /// </summary>
108 /// <param name="threadId"> The ID of the thread to run. </param>
109 /// <param name="content"> The content to send as the body of the request. </param>
110 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
111 /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="content"/> is null. </exception>
112 /// <exception cref="ArgumentException"> <paramref name="threadId"/> is an empty string, and was expected to be non-empty. </exception>
113 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
114 /// <returns> The response returned from the service. </returns>
115 public virtual ClientResult CreateRun(string threadId, BinaryContent content, RequestOptions options = null)
116 {
117 Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
118 Argument.AssertNotNull(content, nameof(content));
119
120 PipelineMessage message = null;
121 try
122 {
123 // Always request the included properties.
124 IEnumerable<InternalIncludedRunStepProperty> includedRunStepProperties = [InternalIncludedRunStepProperty.FileSearchResultContent];
125
126 message = CreateCreateRunRequest(threadId, content, includedRunStepProperties, options);
127 return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
128 }
129 finally
130 {
131 if (options?.BufferResponse != false)
132 {
133 message.Dispose();
134 }
135 }
136 }
137
138 /// <summary>
139 /// [Protocol Method] Modifies a run.
140 /// </summary>
141 /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) that was run. </param>
142 /// <param name="runId"> The ID of the run to modify. </param>
143 /// <param name="content"> The content to send as the body of the request. </param>
144 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
145 /// <exception cref="ArgumentNullException"> <paramref name="threadId"/>, <paramref name="runId"/> or <paramref name="content"/> is null. </exception>
146 /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="runId"/> is an empty string, and was expected to be non-empty. </exception>
147 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
148 /// <returns> The response returned from the service. </returns>
149 public virtual async Task<ClientResult> ModifyRunAsync(string threadId, string runId, BinaryContent content, RequestOptions options = null)
150 {
151 Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
152 Argument.AssertNotNullOrEmpty(runId, nameof(runId));
153 Argument.AssertNotNull(content, nameof(content));
154
155 using PipelineMessage message = CreateModifyRunRequest(threadId, runId, content, options);
156 return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
157 }
158
159 /// <summary>
160 /// [Protocol Method] Modifies a run.
161 /// </summary>
162 /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) that was run. </param>
163 /// <param name="runId"> The ID of the run to modify. </param>
164 /// <param name="content"> The content to send as the body of the request. </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"/>, <paramref name="runId"/> or <paramref name="content"/> 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 ModifyRun(string threadId, string runId, BinaryContent content, RequestOptions options = null)
171 {
172 Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
173 Argument.AssertNotNullOrEmpty(runId, nameof(runId));
174 Argument.AssertNotNull(content, nameof(content));
175
176 using PipelineMessage message = CreateModifyRunRequest(threadId, runId, content, options);
177 return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
178 }
179
180 /// <summary>
181 /// [Protocol Method] Cancels a run that is `in_progress`.
182 /// </summary>
183 /// <param name="threadId"> The ID of the thread to which this run belongs. </param>
184 /// <param name="runId"> The ID of the run to cancel. </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"/> or <paramref name="runId"/> 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> CancelRunAsync(string threadId, string runId, RequestOptions options)
191 {
192 Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
193 Argument.AssertNotNullOrEmpty(runId, nameof(runId));
194
195 using PipelineMessage message = CreateCancelRunRequest(threadId, runId, options);
196 return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
197 }
198
199 /// <summary>
200 /// [Protocol Method] Cancels a run that is `in_progress`.
201 /// </summary>
202 /// <param name="threadId"> The ID of the thread to which this run belongs. </param>
203 /// <param name="runId"> The ID of the run to cancel. </param>
204 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
205 /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="runId"/> is null. </exception>
206 /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="runId"/> is an empty string, and was expected to be non-empty. </exception>
207 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
208 /// <returns> The response returned from the service. </returns>
209 public virtual ClientResult CancelRun(string threadId, string runId, RequestOptions options)
210 {
211 Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
212 Argument.AssertNotNullOrEmpty(runId, nameof(runId));
213
214 using PipelineMessage message = CreateCancelRunRequest(threadId, runId, options);
215 return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
216 }
217
218 /// <summary>
219 /// [Protocol Method] When a run has the `status: "requires_action"` and `required_action.type` is
220 /// `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once
221 /// they're all completed. All outputs must be submitted in a single request.
222 /// </summary>
223 /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) to which this run belongs. </param>
224 /// <param name="runId"> The ID of the run that requires the tool output submission. </param>
225 /// <param name="content"> The content to send as the body of the request. </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"/>, <paramref name="runId"/> or <paramref name="content"/> 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> SubmitToolOutputsToRunAsync(string threadId, string runId, BinaryContent content, RequestOptions options = null)
232 {
233 Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
234 Argument.AssertNotNullOrEmpty(runId, nameof(runId));
235 Argument.AssertNotNull(content, nameof(content));
236
237 PipelineMessage message = null;
238 try
239 {
240 message = CreateSubmitToolOutputsToRunRequest(threadId, runId, content, options);
241 return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
242 }
243 finally
244 {
245 if (options?.BufferResponse != false)
246 {
247 message.Dispose();
248 }
249 }
250 }
251
252 /// <summary>
253 /// [Protocol Method] When a run has the `status: "requires_action"` and `required_action.type` is
254 /// `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once
255 /// they're all completed. All outputs must be submitted in a single request.
256 /// </summary>
257 /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) to which this run belongs. </param>
258 /// <param name="runId"> The ID of the run that requires the tool output submission. </param>
259 /// <param name="content"> The content to send as the body of the request. </param>
260 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
261 /// <exception cref="ArgumentNullException"> <paramref name="threadId"/>, <paramref name="runId"/> or <paramref name="content"/> is null. </exception>
262 /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="runId"/> is an empty string, and was expected to be non-empty. </exception>
263 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
264 /// <returns> The response returned from the service. </returns>
265 public virtual ClientResult SubmitToolOutputsToRun(string threadId, string runId, BinaryContent content, RequestOptions options = null)
266 {
267 Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
268 Argument.AssertNotNullOrEmpty(runId, nameof(runId));
269 Argument.AssertNotNull(content, nameof(content));
270
271 PipelineMessage message = null;
272 try
273 {
274 message = CreateSubmitToolOutputsToRunRequest(threadId, runId, content, options);
275 return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
276 }
277 finally
278 {
279 if (options?.BufferResponse != false)
280 {
281 message.Dispose();
282 }
283 }
284 }
285}
286