openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Assistants/Streaming/RequiredActionUpdate.cs
54lines · modeblame
9f9f2936Jose Arriaga Maldonado2 years ago | 1 | using System.Collections.Generic; |
79014abcShivangiReja1 years ago | 2 | using System.Diagnostics.CodeAnalysis; |
9f9f2936Jose Arriaga Maldonado2 years ago | 3 | using System.Text.Json; |
| 4 | | |
| 5 | namespace 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 ago | 15 | [Experimental("OPENAI001")] |
3e12a623Anne Thompson2 years ago | 16 | public class RequiredActionUpdate : RunUpdate |
9f9f2936Jose Arriaga Maldonado2 years ago | 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) | |
3e12a623Anne Thompson2 years ago | 32 | : base(run, StreamingUpdateReason.RunRequiresAction) |
9f9f2936Jose Arriaga Maldonado2 years ago | 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> | |
3e12a623Anne Thompson2 years ago | 42 | public ThreadRun GetThreadRun() => Value; |
9f9f2936Jose Arriaga Maldonado2 years ago | 43 | |
| 44 | internal static IEnumerable<RequiredActionUpdate> DeserializeRequiredActionUpdates(JsonElement element) | |
| 45 | { | |
e0fee603Jose Arriaga Maldonado1 years ago | 46 | ThreadRun run = ThreadRun.DeserializeThreadRun(element, ModelSerializationExtensions.WireOptions); |
9f9f2936Jose Arriaga Maldonado2 years ago | 47 | List<RequiredActionUpdate> updates = []; |
| 48 | foreach (RequiredAction action in run.RequiredActions ?? []) | |
| 49 | { | |
| 50 | updates.Add(new(run, action)); | |
| 51 | } | |
| 52 | return updates; | |
| 53 | } | |
| 54 | } |