openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.2.0-beta.2

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