Skip to content

Commit

Permalink
adding colors and adding demo for streaming a file extraction assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
BoHomola committed Feb 7, 2025
1 parent f018872 commit 7e8f4a2
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions LlmTornado.Demo/ThreadsDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ public static async Task StreamRun()
{
if (content is MessageContentTextResponse text)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(text.MessageContentTextData?.Value);
Console.ResetColor();
}
}

Expand Down Expand Up @@ -343,7 +345,9 @@ public static async Task StreamFunctionAssistant()
{
if (content is MessageContentTextResponse text)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(text.MessageContentTextData?.Value);
Console.ResetColor();
}
}

Expand All @@ -356,7 +360,10 @@ public static async Task StreamFunctionAssistant()
List<FunctionToolCall> functionCallsWithParameters = run!.RequiredAction!.SubmitToolOutputs.ToolCalls.Where(x => x.Type == ToolCallType.FunctionToolCall).Cast<FunctionToolCall>().ToList();
foreach (FunctionToolCall functionCall in functionCallsWithParameters)
{

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Calling function {functionCall.FunctionCall.Name} with arguments: {functionCall.FunctionCall.Arguments}");
Console.ResetColor();
switch (functionCall.FunctionCall.Name)
{
case "get_weather":
Expand Down Expand Up @@ -390,7 +397,9 @@ public static async Task StreamFunctionAssistant()
{
if (content is MessageContentTextResponse text)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(text.MessageContentTextData?.Value);
Console.ResetColor();
}
}
}
Expand All @@ -407,7 +416,35 @@ public static async Task StreamFunctionAssistant()
{
if (content is MessageContentTextResponse text)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(text.MessageContentTextData?.Value);
Console.ResetColor();
}
}

return ValueTask.CompletedTask;
})
});
}

[TornadoTest]
public static async Task StreamExtractingInfoFromFile()
{
Assistant assistant = await AssistantsDemo.CreateFileSearchAssistant();
generatedThread = await CreateThread();
generatedMessage =
await CreateMessage(generatedThread.Id, "Please summarize the file in 3 sentences from the file.");
await Program.Connect().Threads.StreamRun(generatedThread!.Id, new CreateRunRequest(assistant!.Id), new RunStreamEventHandler
{
OnMessageDelta = (delta =>
{
foreach (MessageContent content in delta.Delta.Content)
{
if (content is MessageContentTextResponse text)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(text.MessageContentTextData?.Value);
Console.ResetColor();
}
}

Expand Down

0 comments on commit 7e8f4a2

Please sign in to comment.