Class ThreadExtensions
public static class ThreadExtensions
  - Inheritance
 - 
      
      ThreadExtensions
 
- Inherited Members
 
Methods
CancelAsync(RunResponse, CancellationToken)
Cancels a run that is InProgress.
public static Task<bool> CancelAsync(this RunResponse run, CancellationToken cancellationToken = default)
  Parameters
runRunResponseRunResponse to cancel.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
CreateMessageAsync(ThreadResponse, Message, CancellationToken)
Create a new message for this thread.
public static Task<MessageResponse> CreateMessageAsync(this ThreadResponse thread, Message request, CancellationToken cancellationToken = default)
  Parameters
threadThreadResponserequestMessagecancellationTokenCancellationTokenOptional, CancellationToken.
Returns
CreateRunAsync(ThreadResponse, AssistantResponse, Action<IServerSentEvent>, CancellationToken)
[Obsolete("use new overload with Func<IServerSentEvent, Task> instead.")]
public static Task<RunResponse> CreateRunAsync(this ThreadResponse thread, AssistantResponse assistant, Action<IServerSentEvent> streamEventHandler, CancellationToken cancellationToken = default)
  Parameters
threadThreadResponseassistantAssistantResponsestreamEventHandlerAction<IServerSentEvent>cancellationTokenCancellationToken
Returns
CreateRunAsync(ThreadResponse, AssistantResponse, Func<IServerSentEvent, Task>, CancellationToken)
Create a run.
public static Task<RunResponse> CreateRunAsync(this ThreadResponse thread, AssistantResponse assistant, Func<IServerSentEvent, Task> streamEventHandler = null, CancellationToken cancellationToken = default)
  Parameters
threadThreadResponseassistantAssistantResponseThe AssistantResponse to use for the run.
streamEventHandlerFunc<IServerSentEvent, Task>Optional, Func<T, TResult> stream callback handler.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
CreateRunAsync(ThreadResponse, CreateRunRequest, Action<IServerSentEvent>, CancellationToken)
[Obsolete("use new overload with Func<IServerSentEvent, Task> instead.")]
public static Task<RunResponse> CreateRunAsync(this ThreadResponse thread, CreateRunRequest request, Action<IServerSentEvent> streamEventHandler, CancellationToken cancellationToken = default)
  Parameters
threadThreadResponserequestCreateRunRequeststreamEventHandlerAction<IServerSentEvent>cancellationTokenCancellationToken
Returns
CreateRunAsync(ThreadResponse, CreateRunRequest, Func<IServerSentEvent, Task>, CancellationToken)
Create a run.
public static Task<RunResponse> CreateRunAsync(this ThreadResponse thread, CreateRunRequest request = null, Func<IServerSentEvent, Task> streamEventHandler = null, CancellationToken cancellationToken = default)
  Parameters
threadThreadResponserequestCreateRunRequeststreamEventHandlerFunc<IServerSentEvent, Task>Optional, Func<T, TResult> stream callback handler.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
DeleteAsync(ThreadResponse, bool, CancellationToken)
Deletes the thread.
public static Task<bool> DeleteAsync(this ThreadResponse thread, bool deleteToolResources = false, CancellationToken cancellationToken = default)
  Parameters
threadThreadResponsedeleteToolResourcesboolOptional, should tool resources, such as vector stores be deleted when this thread is deleted?
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
GetThreadAsync(RunResponse, CancellationToken)
Gets the thread associated to the RunResponse.
public static Task<ThreadResponse> GetThreadAsync(this RunResponse run, CancellationToken cancellationToken = default)
  Parameters
runRunResponsecancellationTokenCancellationTokenOptional, CancellationToken.
Returns
ListMessagesAsync(RunResponse, ListQuery, CancellationToken)
Returns a list of messages for a given thread that the run belongs to.
public static Task<ListResponse<MessageResponse>> ListMessagesAsync(this RunResponse run, ListQuery query = null, CancellationToken cancellationToken = default)
  Parameters
runRunResponsequeryListQuerycancellationTokenCancellationTokenOptional, CancellationToken.
Returns
ListMessagesAsync(ThreadResponse, ListQuery, CancellationToken)
List the messages associated to this thread.
public static Task<ListResponse<MessageResponse>> ListMessagesAsync(this ThreadResponse thread, ListQuery query = null, CancellationToken cancellationToken = default)
  Parameters
threadThreadResponsequeryListQueryOptional, ListQuery.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
ListRunStepsAsync(RunResponse, ListQuery, CancellationToken)
Returns a list of run steps belonging to a run.
public static Task<ListResponse<RunStepResponse>> ListRunStepsAsync(this RunResponse run, ListQuery query = null, CancellationToken cancellationToken = default)
  Parameters
runRunResponseRunResponse to list run steps for.
queryListQueryOptional, ListQuery.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
ListRunsAsync(ThreadResponse, ListQuery, CancellationToken)
Lists all the runs associated to a thread.
public static Task<ListResponse<RunResponse>> ListRunsAsync(this ThreadResponse thread, ListQuery query = null, CancellationToken cancellationToken = default)
  Parameters
threadThreadResponsequeryListQuerycancellationTokenCancellationTokenOptional, CancellationToken.
Returns
ModifyAsync(MessageResponse, IReadOnlyDictionary<string, string>, CancellationToken)
Modify a message.
public static Task<MessageResponse> ModifyAsync(this MessageResponse message, IReadOnlyDictionary<string, string> metadata, CancellationToken cancellationToken = default)
  Parameters
messageMessageResponsemetadataIReadOnlyDictionary<string, string>Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
Remarks
Only the Metadata can be modified.
ModifyAsync(RunResponse, IReadOnlyDictionary<string, string>, CancellationToken)
Modifies a run.
public static Task<RunResponse> ModifyAsync(this RunResponse run, IReadOnlyDictionary<string, string> metadata, CancellationToken cancellationToken = default)
  Parameters
runRunResponseRunResponse to modify.
metadataIReadOnlyDictionary<string, string>Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
Remarks
Only the Metadata can be modified.
ModifyAsync(ThreadResponse, IReadOnlyDictionary<string, string>, CancellationToken)
Modify the thread.
public static Task<ThreadResponse> ModifyAsync(this ThreadResponse thread, IReadOnlyDictionary<string, string> metadata, CancellationToken cancellationToken = default)
  Parameters
threadThreadResponsemetadataIReadOnlyDictionary<string, string>The metadata to set on the thread.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
Remarks
Only the Metadata can be modified.
ModifyMessageAsync(ThreadResponse, string, IReadOnlyDictionary<string, string>, CancellationToken)
Modifies a message.
public static Task<MessageResponse> ModifyMessageAsync(this ThreadResponse thread, string messageId, IReadOnlyDictionary<string, string> metadata, CancellationToken cancellationToken = default)
  Parameters
threadThreadResponsemessageIdstringThe id of the message to modify.
metadataIReadOnlyDictionary<string, string>Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
Remarks
Only the Metadata can be modified.
RetrieveMessageAsync(ThreadResponse, string, CancellationToken)
Retrieve a message.
public static Task<MessageResponse> RetrieveMessageAsync(this ThreadResponse thread, string messageId, CancellationToken cancellationToken = default)
  Parameters
threadThreadResponsemessageIdstringThe id of the message to get.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
RetrieveRunAsync(ThreadResponse, string, CancellationToken)
Retrieves a run.
public static Task<RunResponse> RetrieveRunAsync(this ThreadResponse thread, string runId, CancellationToken cancellationToken = default)
  Parameters
threadThreadResponseThe thread that was run.
runIdstringThe id of the run to retrieve.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
RetrieveRunStepAsync(RunResponse, string, CancellationToken)
Retrieves a run step.
public static Task<RunStepResponse> RetrieveRunStepAsync(this RunResponse run, string runStepId, CancellationToken cancellationToken = default)
  Parameters
runRunResponseRunResponse to retrieve step for.
runStepIdstringId of the run step.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
SubmitToolOutputsAsync(RunResponse, SubmitToolOutputsRequest, Action<IServerSentEvent>, CancellationToken)
[Obsolete("use new overload with Func<IServerSentEvent, Task> instead.")]
public static Task<RunResponse> SubmitToolOutputsAsync(this RunResponse run, SubmitToolOutputsRequest request, Action<IServerSentEvent> streamEventHandler, CancellationToken cancellationToken = default)
  Parameters
runRunResponserequestSubmitToolOutputsRequeststreamEventHandlerAction<IServerSentEvent>cancellationTokenCancellationToken
Returns
SubmitToolOutputsAsync(RunResponse, SubmitToolOutputsRequest, Func<IServerSentEvent, Task>, CancellationToken)
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.
public static Task<RunResponse> SubmitToolOutputsAsync(this RunResponse run, SubmitToolOutputsRequest request, Func<IServerSentEvent, Task> streamEventHandler = null, CancellationToken cancellationToken = default)
  Parameters
runRunResponseRunResponse to submit outputs for.
requestSubmitToolOutputsRequeststreamEventHandlerFunc<IServerSentEvent, Task>Optional, Func<T, TResult> stream callback handler.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
SubmitToolOutputsAsync(RunResponse, IEnumerable<ToolOutput>, Action<IServerSentEvent>, CancellationToken)
[Obsolete("use new overload with Func<IServerSentEvent, Task> instead.")]
public static Task<RunResponse> SubmitToolOutputsAsync(this RunResponse run, IEnumerable<ToolOutput> outputs, Action<IServerSentEvent> streamEventHandler, CancellationToken cancellationToken = default)
  Parameters
runRunResponseoutputsIEnumerable<ToolOutput>streamEventHandlerAction<IServerSentEvent>cancellationTokenCancellationToken
Returns
SubmitToolOutputsAsync(RunResponse, IEnumerable<ToolOutput>, Func<IServerSentEvent, Task>, CancellationToken)
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.
public static Task<RunResponse> SubmitToolOutputsAsync(this RunResponse run, IEnumerable<ToolOutput> outputs, Func<IServerSentEvent, Task> streamEventHandler = null, CancellationToken cancellationToken = default)
  Parameters
runRunResponseRunResponse to submit outputs for.
outputsIEnumerable<ToolOutput>streamEventHandlerFunc<IServerSentEvent, Task>Optional, Func<T, TResult> stream callback handler.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
UpdateAsync(MessageResponse, CancellationToken)
Retrieve a message.
public static Task<MessageResponse> UpdateAsync(this MessageResponse message, CancellationToken cancellationToken = default)
  Parameters
messageMessageResponsecancellationTokenCancellationTokenOptional, CancellationToken.
Returns
UpdateAsync(RunResponse, CancellationToken)
Get the latest status of the RunResponse.
public static Task<RunResponse> UpdateAsync(this RunResponse run, CancellationToken cancellationToken = default)
  Parameters
runRunResponsecancellationTokenCancellationTokenOptional, CancellationToken.
Returns
UpdateAsync(RunStepResponse, CancellationToken)
Retrieves a run step.
public static Task<RunStepResponse> UpdateAsync(this RunStepResponse runStep, CancellationToken cancellationToken = default)
  Parameters
runStepRunStepResponseRunStepResponse to retrieve.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
UpdateAsync(ThreadResponse, CancellationToken)
Updates this thread with the latest snapshot from OpenAI.
public static Task<ThreadResponse> UpdateAsync(this ThreadResponse thread, CancellationToken cancellationToken = default)
  Parameters
threadThreadResponsecancellationTokenCancellationTokenOptional, CancellationToken.
Returns
WaitForStatusChangeAsync(RunResponse, int?, int?, CancellationToken)
Waits for Status to change.
public static Task<RunResponse> WaitForStatusChangeAsync(this RunResponse run, int? pollingInterval = null, int? timeout = null, CancellationToken cancellationToken = default)
  Parameters
runRunResponsepollingIntervalint?Optional, time in milliseconds to wait before polling status.
timeoutint?Optional, timeout in seconds to cancel polling.
Defaults to 30 seconds.
Set to -1 for indefinite.cancellationTokenCancellationTokenOptional, CancellationToken.