diff --git a/labs/035-assistants-dotnet/OpenAIExtensions.cs b/labs/035-assistants-dotnet/OpenAIExtensions.cs index 10b0554..f312cf1 100644 --- a/labs/035-assistants-dotnet/OpenAIExtensions.cs +++ b/labs/035-assistants-dotnet/OpenAIExtensions.cs @@ -1,3 +1,5 @@ +using System.Text; +using System.Text.Json; using OpenAI; using OpenAI.Assistants; #pragma warning disable OPENAI001 @@ -43,6 +45,7 @@ public static async IAsyncEnumerable AddMessageAndRunToCompletion(this A var asyncUpdate = client.CreateRunStreamingAsync(threadId, assistantId); ThreadRun? currentRun; + var codeInterpreterCode = new StringBuilder(); do { currentRun = null; @@ -68,6 +71,11 @@ public static async IAsyncEnumerable AddMessageAndRunToCompletion(this A outputsToSumit.Add(new ToolOutput(requiredActionUpdate.ToolCallId, functionResponse)); } + else if (update is RunStepDetailsUpdate runStepDetailsUpdate + && !string.IsNullOrEmpty(runStepDetailsUpdate.CodeInterpreterInput)) + { + codeInterpreterCode.Append(runStepDetailsUpdate.CodeInterpreterInput); + } else if (update is MessageContentUpdate contentUpdate) { yield return contentUpdate.Text; @@ -80,6 +88,12 @@ public static async IAsyncEnumerable AddMessageAndRunToCompletion(this A } } while (currentRun?.Status.IsTerminal is false); + + if (codeInterpreterCode.Length > 0) + { + Console.WriteLine("\n\nCODE INTERPRETER:"); + Console.WriteLine(codeInterpreterCode.ToString()); + } } public static async Task GetLatestMessage(this AssistantClient client, string threadId)