Skip to content

Commit

Permalink
Add code interpreter logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rstropek committed Jun 11, 2024
1 parent f11e034 commit 4263163
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions labs/035-assistants-dotnet/OpenAIExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Text;
using System.Text.Json;
using OpenAI;
using OpenAI.Assistants;
#pragma warning disable OPENAI001
Expand Down Expand Up @@ -43,6 +45,7 @@ public static async IAsyncEnumerable<string> AddMessageAndRunToCompletion(this A
var asyncUpdate = client.CreateRunStreamingAsync(threadId, assistantId);

ThreadRun? currentRun;
var codeInterpreterCode = new StringBuilder();
do
{
currentRun = null;
Expand All @@ -68,6 +71,11 @@ public static async IAsyncEnumerable<string> 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;
Expand All @@ -80,6 +88,12 @@ public static async IAsyncEnumerable<string> 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<string?> GetLatestMessage(this AssistantClient client, string threadId)
Expand Down

0 comments on commit 4263163

Please sign in to comment.