using Microsoft.TypeSpec.Generator.Customizations; using System; using System.ClientModel; using System.ClientModel.Primitives; using System.Collections.Generic; using System.Threading.Tasks; namespace OpenAI.Assistants; [CodeGenSuppress("CreateRunAsync", typeof(string), typeof(BinaryContent), typeof(IEnumerable), typeof(RequestOptions))] [CodeGenSuppress("CreateRun", typeof(string), typeof(BinaryContent), typeof(IEnumerable), typeof(RequestOptions))] [CodeGenSuppress("CreateThreadAndRunAsync", typeof(string), typeof(BinaryContent), typeof(RequestOptions))] [CodeGenSuppress("CreateThreadAndRun", typeof(string), typeof(BinaryContent), typeof(RequestOptions))] [CodeGenSuppress("SubmitToolOutputsToRunAsync", typeof(string), typeof(string), typeof(string), typeof(BinaryContent),typeof(RequestOptions))] [CodeGenSuppress("SubmitToolOutputsToRun", typeof(string), typeof(string), typeof(string), typeof(BinaryContent), typeof(RequestOptions))] internal partial class InternalAssistantRunClient { /// /// [Protocol Method] Create a thread and run it in one request. /// /// The content to send as the body of the request. /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// Service returned a non-success status code. /// The response returned from the service. public virtual async Task CreateThreadAndRunAsync(BinaryContent content, RequestOptions options = null) { Argument.AssertNotNull(content, nameof(content)); PipelineMessage message = null; try { message = CreateCreateThreadAndRunRequest(content, options); return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } finally { if (options?.BufferResponse != false) { message.Dispose(); } } } /// /// [Protocol Method] Create a thread and run it in one request. /// /// The content to send as the body of the request. /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// Service returned a non-success status code. /// The response returned from the service. public virtual ClientResult CreateThreadAndRun(BinaryContent content, RequestOptions options = null) { Argument.AssertNotNull(content, nameof(content)); PipelineMessage message = null; try { message = CreateCreateThreadAndRunRequest(content, options); return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } finally { if (options?.BufferResponse != false) { message.Dispose(); } } } /// /// [Protocol Method] Create a run. /// /// The ID of the thread to run. /// The content to send as the body of the request. /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// or is null. /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. public virtual async Task CreateRunAsync(string threadId, BinaryContent content, RequestOptions options = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNull(content, nameof(content)); PipelineMessage message = null; try { // Always request the included properties. IEnumerable includedRunStepProperties = [InternalIncludedRunStepProperty.FileSearchResultContent]; message = CreateCreateRunRequest(threadId, content, includedRunStepProperties, options); return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } finally { if (options?.BufferResponse != false) { message.Dispose(); } } } /// /// [Protocol Method] Create a run. /// /// The ID of the thread to run. /// The content to send as the body of the request. /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// or is null. /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. public virtual ClientResult CreateRun(string threadId, BinaryContent content, RequestOptions options = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNull(content, nameof(content)); PipelineMessage message = null; try { // Always request the included properties. IEnumerable includedRunStepProperties = [InternalIncludedRunStepProperty.FileSearchResultContent]; message = CreateCreateRunRequest(threadId, content, includedRunStepProperties, options); return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } finally { if (options?.BufferResponse != false) { message.Dispose(); } } } /// /// [Protocol Method] Modifies a run. /// /// The ID of the [thread](/docs/api-reference/threads) that was run. /// The ID of the run to modify. /// The content to send as the body of the request. /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// , or is null. /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. public virtual async Task ModifyRunAsync(string threadId, string runId, BinaryContent content, RequestOptions options = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNull(content, nameof(content)); using PipelineMessage message = CreateModifyRunRequest(threadId, runId, content, options); return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// /// [Protocol Method] Modifies a run. /// /// The ID of the [thread](/docs/api-reference/threads) that was run. /// The ID of the run to modify. /// The content to send as the body of the request. /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// , or is null. /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. public virtual ClientResult ModifyRun(string threadId, string runId, BinaryContent content, RequestOptions options = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNull(content, nameof(content)); using PipelineMessage message = CreateModifyRunRequest(threadId, runId, content, options); return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// /// [Protocol Method] Cancels a run that is `in_progress`. /// /// The ID of the thread to which this run belongs. /// The ID of the run to cancel. /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// or is null. /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. public virtual async Task CancelRunAsync(string threadId, string runId, RequestOptions options) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); using PipelineMessage message = CreateCancelRunRequest(threadId, runId, options); return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } /// /// [Protocol Method] Cancels a run that is `in_progress`. /// /// The ID of the thread to which this run belongs. /// The ID of the run to cancel. /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// or is null. /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. public virtual ClientResult CancelRun(string threadId, string runId, RequestOptions options) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); using PipelineMessage message = CreateCancelRunRequest(threadId, runId, options); return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } /// /// [Protocol Method] When a run has the `status: "requires_action"` and `required_action.type` is /// `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once /// they're all completed. All outputs must be submitted in a single request. /// /// The ID of the [thread](/docs/api-reference/threads) to which this run belongs. /// The ID of the run that requires the tool output submission. /// The content to send as the body of the request. /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// , or is null. /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. public virtual async Task SubmitToolOutputsToRunAsync(string threadId, string runId, BinaryContent content, RequestOptions options = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNull(content, nameof(content)); PipelineMessage message = null; try { message = CreateSubmitToolOutputsToRunRequest(threadId, runId, content, options); return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); } finally { if (options?.BufferResponse != false) { message.Dispose(); } } } /// /// [Protocol Method] When a run has the `status: "requires_action"` and `required_action.type` is /// `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once /// they're all completed. All outputs must be submitted in a single request. /// /// The ID of the [thread](/docs/api-reference/threads) to which this run belongs. /// The ID of the run that requires the tool output submission. /// The content to send as the body of the request. /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// , or is null. /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. public virtual ClientResult SubmitToolOutputsToRun(string threadId, string runId, BinaryContent content, RequestOptions options = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNull(content, nameof(content)); PipelineMessage message = null; try { message = CreateSubmitToolOutputsToRunRequest(threadId, runId, content, options); return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); } finally { if (options?.BufferResponse != false) { message.Dispose(); } } } }