From 479779e908af392215f71a964ae253a0f717bbf8 Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Fri, 17 Nov 2023 01:28:05 +0000 Subject: [PATCH] Some minor cleanup on example code: - Removed special case for exit - Added a wait at the end of batched decoding --- LLama.Examples/Examples/BatchedDecoding.cs | 6 ++- LLama.Examples/Examples/Runner.cs | 44 ++++++++++------------ 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/LLama.Examples/Examples/BatchedDecoding.cs b/LLama.Examples/Examples/BatchedDecoding.cs index 80ce80ae..6f36358d 100644 --- a/LLama.Examples/Examples/BatchedDecoding.cs +++ b/LLama.Examples/Examples/BatchedDecoding.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using System.Security.Cryptography; using System.Text; using LLama.Common; using LLama.Native; @@ -17,7 +16,7 @@ public class BatchedDecoding private const int top_k = 80; private const float top_p = 0.8f; - private const float temp = 0.5f; + private const float temp = 0.75f; public static async Task Run() { @@ -173,5 +172,8 @@ public class BatchedDecoding Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(text); } + + Console.WriteLine("Press any key to exit demo"); + Console.ReadKey(true); } } \ No newline at end of file diff --git a/LLama.Examples/Examples/Runner.cs b/LLama.Examples/Examples/Runner.cs index 572d6b49..f2f1351f 100644 --- a/LLama.Examples/Examples/Runner.cs +++ b/LLama.Examples/Examples/Runner.cs @@ -4,27 +4,28 @@ namespace LLama.Examples.Examples; public class Runner { - static Dictionary> Examples = new() + private static readonly Dictionary> Examples = new() { - {"Run a chat session without stripping the role names.", () => ChatSessionWithRoleName.Run()}, - {"Run a chat session with the role names stripped.",()=> ChatSessionStripRoleName.Run()}, - {"Interactive mode chat by using executor.",()=> InteractiveModeExecute.Run()}, - {"Instruct mode chat by using executor.",()=> InstructModeExecute.Run()}, - {"Stateless mode chat by using executor.",()=> StatelessModeExecute.Run()}, - {"Load and save chat session.",()=> SaveAndLoadSession.Run()}, - {"Load and save state of model and executor.",()=> LoadAndSaveState.Run()}, - {"Get embeddings from LLama model.",()=> Task.Run(GetEmbeddings.Run)}, - {"Quantize the model.",()=> Task.Run(QuantizeModel.Run)}, - {"Automatic conversation.",()=> TalkToYourself.Run()}, - {"Constrain response to json format using grammar.",()=> GrammarJsonResponse.Run()}, - {"Semantic Kernel Prompt.",()=> SemanticKernelPrompt.Run()}, - {"Semantic Kernel Chat.",()=> SemanticKernelChat.Run()}, - {"Semantic Kernel Memory.",()=> SemanticKernelMemory.Run()}, - {"Coding Assistant.",()=> CodingAssistant.Run()}, - {"Batch Decoding.",()=> BatchedDecoding.Run()}, - {"SK Kernel Memory.",()=> KernelMemory.Run()}, - {"Exit", ()=> Task.CompletedTask} + { "Run a chat session without stripping the role names.", ChatSessionWithRoleName.Run }, + { "Run a chat session with the role names stripped.", ChatSessionStripRoleName.Run }, + { "Interactive mode chat by using executor.", InteractiveModeExecute.Run }, + { "Instruct mode chat by using executor.", InstructModeExecute.Run }, + { "Stateless mode chat by using executor.", StatelessModeExecute.Run }, + { "Load and save chat session.", SaveAndLoadSession.Run }, + { "Load and save state of model and executor.", LoadAndSaveState.Run }, + { "Get embeddings from LLama model.", () => Task.Run(GetEmbeddings.Run) }, + { "Quantize the model.", () => Task.Run(QuantizeModel.Run) }, + { "Automatic conversation.", TalkToYourself.Run }, + { "Constrain response to json format using grammar.", GrammarJsonResponse.Run }, + { "Semantic Kernel Prompt.", SemanticKernelPrompt.Run }, + { "Semantic Kernel Chat.", SemanticKernelChat.Run }, + { "Semantic Kernel Memory.", SemanticKernelMemory.Run }, + { "Coding Assistant.", CodingAssistant.Run }, + { "Batch Decoding.", BatchedDecoding.Run }, + { "SK Kernel Memory.", KernelMemory.Run }, + { "Exit", async () => Environment.Exit(0) } }; + public static async Task Run() { AnsiConsole.Write(new Rule("LLamaSharp Examples")); @@ -36,13 +37,8 @@ public class Runner .Title("Please choose[green] an example[/] to run: ") .AddChoices(Examples.Keys)); - if (Examples.TryGetValue(choice, out var example)) { - if (choice == "Exit") - { - break; - } AnsiConsole.Write(new Rule(choice)); await example(); }