openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0-beta.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Custom/Assistants/Streaming/RequiredActionUpdate.cs

54lines · modecode

1using System.Collections.Generic;
2using System.Text.Json;
3
4namespace OpenAI.Assistants;
5
6/// <summary>
7/// The update type presented when the status of a <see cref="ThreadRun"/> has changed to <c>requires_action</c>,
8/// indicating that tool output submission or another intervention is needed for the run to continue.
9/// </summary>
10/// <remarks>
11/// Distinct <see cref="RequiredActionUpdate"/> instances will generated for each required action, meaning that
12/// parallel function calling will present multiple updates even if the tool calls arrive at the same time.
13/// </remarks>
14public class RequiredActionUpdate : StreamingUpdate
15{
16 /// <inheritdoc cref="InternalRequiredFunctionToolCall.InternalName"/>
17 public string FunctionName => AsFunctionCall?.FunctionName;
18
19 /// <inheritdoc cref="InternalRequiredFunctionToolCall.InternalArguments"/>
20 public string FunctionArguments => AsFunctionCall?.FunctionArguments;
21
22 /// <inheritdoc cref="InternalRequiredFunctionToolCall.Id"/>
23 public string ToolCallId => AsFunctionCall?.Id;
24
25 private InternalRequiredFunctionToolCall AsFunctionCall => _requiredAction as InternalRequiredFunctionToolCall;
26
27 private readonly ThreadRun _run;
28 private readonly RequiredAction _requiredAction;
29
30 internal RequiredActionUpdate(ThreadRun run, RequiredAction action)
31 : base(StreamingUpdateReason.RunRequiresAction)
32 {
33 _run = run;
34 _requiredAction = action;
35 }
36
37 /// <summary>
38 /// Gets the full, deserialized <see cref="ThreadRun"/> instance associated with this streaming required action
39 /// update.
40 /// </summary>
41 /// <returns></returns>
42 public ThreadRun GetThreadRun() => _run;
43
44 internal static IEnumerable<RequiredActionUpdate> DeserializeRequiredActionUpdates(JsonElement element)
45 {
46 ThreadRun run = ThreadRun.DeserializeThreadRun(element);
47 List<RequiredActionUpdate> updates = [];
48 foreach (RequiredAction action in run.RequiredActions ?? [])
49 {
50 updates.Add(new(run, action));
51 }
52 return updates;
53 }
54}