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 · modeblame

9f9f2936Jose Arriaga Maldonado2 years ago1using System.Collections.Generic;
79014abcShivangiReja1 years ago2using System.Diagnostics.CodeAnalysis;
9f9f2936Jose Arriaga Maldonado2 years ago3using 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>
79014abcShivangiReja1 years ago15[Experimental("OPENAI001")]
3e12a623Anne Thompson2 years ago16public class RequiredActionUpdate : RunUpdate
9f9f2936Jose Arriaga Maldonado2 years ago17{
18/// <inheritdoc cref="InternalRequiredFunctionToolCall.InternalName"/>
19public string FunctionName => AsFunctionCall?.FunctionName;
20
21/// <inheritdoc cref="InternalRequiredFunctionToolCall.InternalArguments"/>
22public string FunctionArguments => AsFunctionCall?.FunctionArguments;
23
24/// <inheritdoc cref="InternalRequiredFunctionToolCall.Id"/>
25public string ToolCallId => AsFunctionCall?.Id;
26
27private InternalRequiredFunctionToolCall AsFunctionCall => _requiredAction as InternalRequiredFunctionToolCall;
28
29private readonly RequiredAction _requiredAction;
30
31internal RequiredActionUpdate(ThreadRun run, RequiredAction action)
3e12a623Anne Thompson2 years ago32: base(run, StreamingUpdateReason.RunRequiresAction)
9f9f2936Jose Arriaga Maldonado2 years ago33{
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>
3e12a623Anne Thompson2 years ago42public ThreadRun GetThreadRun() => Value;
9f9f2936Jose Arriaga Maldonado2 years ago43
44internal static IEnumerable<RequiredActionUpdate> DeserializeRequiredActionUpdates(JsonElement element)
45{
e0fee603Jose Arriaga Maldonado1 years ago46ThreadRun run = ThreadRun.DeserializeThreadRun(element, ModelSerializationExtensions.WireOptions);
9f9f2936Jose Arriaga Maldonado2 years ago47List<RequiredActionUpdate> updates = [];
48foreach (RequiredAction action in run.RequiredActions ?? [])
49{
50updates.Add(new(run, action));
51}
52return updates;
53}
54}