diff --git a/LLama.Examples/NewVersion/BatchedDecoding.cs b/LLama.Examples/Examples/BatchedDecoding.cs similarity index 99% rename from LLama.Examples/NewVersion/BatchedDecoding.cs rename to LLama.Examples/Examples/BatchedDecoding.cs index ad29703a3..80ce80ae9 100644 --- a/LLama.Examples/NewVersion/BatchedDecoding.cs +++ b/LLama.Examples/Examples/BatchedDecoding.cs @@ -4,7 +4,7 @@ using LLama.Common; using LLama.Native; -namespace LLama.Examples.NewVersion; +namespace LLama.Examples.Examples; /// /// This demonstrates generating multiple replies to the same prompt, with a shared cache diff --git a/LLama.Examples/NewVersion/ChatSessionStripRoleName.cs b/LLama.Examples/Examples/ChatSessionStripRoleName.cs similarity index 97% rename from LLama.Examples/NewVersion/ChatSessionStripRoleName.cs rename to LLama.Examples/Examples/ChatSessionStripRoleName.cs index c3cae9301..41362c4a3 100644 --- a/LLama.Examples/NewVersion/ChatSessionStripRoleName.cs +++ b/LLama.Examples/Examples/ChatSessionStripRoleName.cs @@ -1,6 +1,6 @@ using LLama.Common; -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class ChatSessionStripRoleName { diff --git a/LLama.Examples/NewVersion/ChatSessionWithRoleName.cs b/LLama.Examples/Examples/ChatSessionWithRoleName.cs similarity index 97% rename from LLama.Examples/NewVersion/ChatSessionWithRoleName.cs rename to LLama.Examples/Examples/ChatSessionWithRoleName.cs index 70dbe7576..c9ea9023e 100644 --- a/LLama.Examples/NewVersion/ChatSessionWithRoleName.cs +++ b/LLama.Examples/Examples/ChatSessionWithRoleName.cs @@ -1,6 +1,6 @@ using LLama.Common; -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class ChatSessionWithRoleName { diff --git a/LLama.Examples/NewVersion/CodingAssistant.cs b/LLama.Examples/Examples/CodingAssistant.cs similarity index 99% rename from LLama.Examples/NewVersion/CodingAssistant.cs rename to LLama.Examples/Examples/CodingAssistant.cs index 727dd0103..b51b5f1eb 100644 --- a/LLama.Examples/NewVersion/CodingAssistant.cs +++ b/LLama.Examples/Examples/CodingAssistant.cs @@ -1,4 +1,4 @@ -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { using LLama.Common; using System; diff --git a/LLama.Examples/NewVersion/GetEmbeddings.cs b/LLama.Examples/Examples/GetEmbeddings.cs similarity index 95% rename from LLama.Examples/NewVersion/GetEmbeddings.cs rename to LLama.Examples/Examples/GetEmbeddings.cs index fe9e3ea80..35de82ebb 100644 --- a/LLama.Examples/NewVersion/GetEmbeddings.cs +++ b/LLama.Examples/Examples/GetEmbeddings.cs @@ -1,6 +1,6 @@ using LLama.Common; -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class GetEmbeddings { diff --git a/LLama.Examples/NewVersion/GrammarJsonResponse.cs b/LLama.Examples/Examples/GrammarJsonResponse.cs similarity index 98% rename from LLama.Examples/NewVersion/GrammarJsonResponse.cs rename to LLama.Examples/Examples/GrammarJsonResponse.cs index 55405d144..0d914f316 100644 --- a/LLama.Examples/NewVersion/GrammarJsonResponse.cs +++ b/LLama.Examples/Examples/GrammarJsonResponse.cs @@ -1,7 +1,7 @@ using LLama.Common; using LLama.Grammars; -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class GrammarJsonResponse { diff --git a/LLama.Examples/NewVersion/InstructModeExecute.cs b/LLama.Examples/Examples/InstructModeExecute.cs similarity index 97% rename from LLama.Examples/NewVersion/InstructModeExecute.cs rename to LLama.Examples/Examples/InstructModeExecute.cs index 6a9912d9b..7e3e09720 100644 --- a/LLama.Examples/NewVersion/InstructModeExecute.cs +++ b/LLama.Examples/Examples/InstructModeExecute.cs @@ -1,6 +1,6 @@ using LLama.Common; -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class InstructModeExecute { diff --git a/LLama.Examples/NewVersion/InteractiveModeExecute.cs b/LLama.Examples/Examples/InteractiveModeExecute.cs similarity index 97% rename from LLama.Examples/NewVersion/InteractiveModeExecute.cs rename to LLama.Examples/Examples/InteractiveModeExecute.cs index 8bc002eb1..0cff5ec94 100644 --- a/LLama.Examples/NewVersion/InteractiveModeExecute.cs +++ b/LLama.Examples/Examples/InteractiveModeExecute.cs @@ -1,6 +1,6 @@ using LLama.Common; -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class InteractiveModeExecute { diff --git a/LLama.Examples/NewVersion/KernelMemory.cs b/LLama.Examples/Examples/KernelMemory.cs similarity index 97% rename from LLama.Examples/NewVersion/KernelMemory.cs rename to LLama.Examples/Examples/KernelMemory.cs index 8320acf52..0f63447f4 100644 --- a/LLama.Examples/NewVersion/KernelMemory.cs +++ b/LLama.Examples/Examples/KernelMemory.cs @@ -7,7 +7,7 @@ using Microsoft.KernelMemory; using Microsoft.KernelMemory.Handlers; -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class KernelMemory { diff --git a/LLama.Examples/NewVersion/LoadAndSaveSession.cs b/LLama.Examples/Examples/LoadAndSaveSession.cs similarity index 98% rename from LLama.Examples/NewVersion/LoadAndSaveSession.cs rename to LLama.Examples/Examples/LoadAndSaveSession.cs index 9e6116ce4..910680911 100644 --- a/LLama.Examples/NewVersion/LoadAndSaveSession.cs +++ b/LLama.Examples/Examples/LoadAndSaveSession.cs @@ -1,6 +1,6 @@ using LLama.Common; -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class SaveAndLoadSession { diff --git a/LLama.Examples/NewVersion/LoadAndSaveState.cs b/LLama.Examples/Examples/LoadAndSaveState.cs similarity index 98% rename from LLama.Examples/NewVersion/LoadAndSaveState.cs rename to LLama.Examples/Examples/LoadAndSaveState.cs index 2546a4964..d4874ff3c 100644 --- a/LLama.Examples/NewVersion/LoadAndSaveState.cs +++ b/LLama.Examples/Examples/LoadAndSaveState.cs @@ -1,6 +1,6 @@ using LLama.Common; -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class LoadAndSaveState { diff --git a/LLama.Examples/NewVersion/QuantizeModel.cs b/LLama.Examples/Examples/QuantizeModel.cs similarity index 95% rename from LLama.Examples/NewVersion/QuantizeModel.cs rename to LLama.Examples/Examples/QuantizeModel.cs index 71966af8f..1a67f750e 100644 --- a/LLama.Examples/NewVersion/QuantizeModel.cs +++ b/LLama.Examples/Examples/QuantizeModel.cs @@ -1,4 +1,4 @@ -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class QuantizeModel { diff --git a/LLama.Examples/Examples/Runner.cs b/LLama.Examples/Examples/Runner.cs new file mode 100644 index 000000000..572d6b49c --- /dev/null +++ b/LLama.Examples/Examples/Runner.cs @@ -0,0 +1,53 @@ +using Spectre.Console; + +namespace LLama.Examples.Examples; + +public class Runner +{ + static 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} + }; + public static async Task Run() + { + AnsiConsole.Write(new Rule("LLamaSharp Examples")); + + while (true) + { + var choice = AnsiConsole.Prompt( + new SelectionPrompt() + .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(); + } + + AnsiConsole.Clear(); + } + } +} diff --git a/LLama.Examples/NewVersion/SemanticKernelChat.cs b/LLama.Examples/Examples/SemanticKernelChat.cs similarity index 98% rename from LLama.Examples/NewVersion/SemanticKernelChat.cs rename to LLama.Examples/Examples/SemanticKernelChat.cs index 4f27bf659..284237f06 100644 --- a/LLama.Examples/NewVersion/SemanticKernelChat.cs +++ b/LLama.Examples/Examples/SemanticKernelChat.cs @@ -3,7 +3,7 @@ using Microsoft.SemanticKernel.AI.ChatCompletion; using LLamaSharp.SemanticKernel.ChatCompletion; -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class SemanticKernelChat { diff --git a/LLama.Examples/NewVersion/SemanticKernelMemory.cs b/LLama.Examples/Examples/SemanticKernelMemory.cs similarity index 99% rename from LLama.Examples/NewVersion/SemanticKernelMemory.cs rename to LLama.Examples/Examples/SemanticKernelMemory.cs index 61ea2f427..980d74bbf 100644 --- a/LLama.Examples/NewVersion/SemanticKernelMemory.cs +++ b/LLama.Examples/Examples/SemanticKernelMemory.cs @@ -5,7 +5,7 @@ using Microsoft.SemanticKernel.AI.Embeddings; using Microsoft.SemanticKernel.Plugins.Memory; -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class SemanticKernelMemory { diff --git a/LLama.Examples/NewVersion/SemanticKernelPrompt.cs b/LLama.Examples/Examples/SemanticKernelPrompt.cs similarity index 98% rename from LLama.Examples/NewVersion/SemanticKernelPrompt.cs rename to LLama.Examples/Examples/SemanticKernelPrompt.cs index d744b7630..c4974d676 100644 --- a/LLama.Examples/NewVersion/SemanticKernelPrompt.cs +++ b/LLama.Examples/Examples/SemanticKernelPrompt.cs @@ -5,7 +5,7 @@ using Microsoft.SemanticKernel.AI.TextCompletion; using LLamaSharp.SemanticKernel.TextCompletion; -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class SemanticKernelPrompt { diff --git a/LLama.Examples/NewVersion/StatelessModeExecute.cs b/LLama.Examples/Examples/StatelessModeExecute.cs similarity index 98% rename from LLama.Examples/NewVersion/StatelessModeExecute.cs rename to LLama.Examples/Examples/StatelessModeExecute.cs index f4f030d95..47dd0bbd1 100644 --- a/LLama.Examples/NewVersion/StatelessModeExecute.cs +++ b/LLama.Examples/Examples/StatelessModeExecute.cs @@ -1,7 +1,7 @@ using LLama.Common; using LLama.Examples.Extensions; -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class StatelessModeExecute { diff --git a/LLama.Examples/NewVersion/TalkToYourself.cs b/LLama.Examples/Examples/TalkToYourself.cs similarity index 98% rename from LLama.Examples/NewVersion/TalkToYourself.cs rename to LLama.Examples/Examples/TalkToYourself.cs index 80d129ca1..1e94bfe00 100644 --- a/LLama.Examples/NewVersion/TalkToYourself.cs +++ b/LLama.Examples/Examples/TalkToYourself.cs @@ -3,7 +3,7 @@ using LLama.Abstractions; using LLama.Common; -namespace LLama.Examples.NewVersion +namespace LLama.Examples.Examples { public class TalkToYourself { diff --git a/LLama.Examples/NewVersion/TestRunner.cs b/LLama.Examples/NewVersion/TestRunner.cs deleted file mode 100644 index a21a2eed4..000000000 --- a/LLama.Examples/NewVersion/TestRunner.cs +++ /dev/null @@ -1,112 +0,0 @@ -namespace LLama.Examples.NewVersion -{ - public class NewVersionTestRunner - { - public static async Task Run() - { - Console.WriteLine("================LLamaSharp Examples (New Version)==================\n"); - - Console.WriteLine("Please input a number to choose an example to run:"); - Console.WriteLine("0: Run a chat session without stripping the role names."); - Console.WriteLine("1: Run a chat session with the role names stripped."); - Console.WriteLine("2: Interactive mode chat by using executor."); - Console.WriteLine("3: Instruct mode chat by using executor."); - Console.WriteLine("4: Stateless mode chat by using executor."); - Console.WriteLine("5: Load and save chat session."); - Console.WriteLine("6: Load and save state of model and executor."); - Console.WriteLine("7: Get embeddings from LLama model."); - Console.WriteLine("8: Quantize the model."); - Console.WriteLine("9: Automatic conversation."); - Console.WriteLine("10: Constrain response to json format using grammar."); - Console.WriteLine("11: Semantic Kernel Prompt."); - Console.WriteLine("12: Semantic Kernel Chat."); - Console.WriteLine("13: Semantic Kernel Memory."); - Console.WriteLine("14: Coding Assistant."); - Console.WriteLine("15: Batch Decoding."); - Console.WriteLine("16: SK Kernel Memory."); - - while (true) - { - Console.Write("\nYour choice: "); - int choice = int.Parse(Console.ReadLine()); - - if (choice == 0) - { - await ChatSessionWithRoleName.Run(); - } - else if (choice == 1) - { - await ChatSessionStripRoleName.Run(); - } - else if (choice == 2) - { - await InteractiveModeExecute.Run(); - } - else if (choice == 3) - { - await InstructModeExecute.Run(); - } - else if (choice == 4) - { - await StatelessModeExecute.Run(); - } - else if (choice == 5) - { - await SaveAndLoadSession.Run(); - } - else if (choice == 6) - { - await LoadAndSaveState.Run(); - } - else if (choice == 7) - { - GetEmbeddings.Run(); - } - else if (choice == 8) - { - QuantizeModel.Run(); - } - else if (choice == 9) - { - await TalkToYourself.Run(); - } - else if (choice == 10) - { - await GrammarJsonResponse.Run(); - } - else if (choice == 11) - { - await SemanticKernelPrompt.Run(); - } - else if (choice == 12) - { - await SemanticKernelChat.Run(); - } - else if (choice == 13) - { - await SemanticKernelMemory.Run(); - } - else if (choice == 14) - { - await CodingAssistant.Run(); - } - else if (choice == 15) - { - await BatchedDecoding.Run(); - } - else if (choice == 16) - { - await KernelMemory.Run(); - } - else - { - Console.WriteLine("Cannot parse your choice. Please select again."); - continue; - } - break; - } - } - } - - -} diff --git a/LLama.Examples/Program.cs b/LLama.Examples/Program.cs index ee90ac841..9feb62023 100644 --- a/LLama.Examples/Program.cs +++ b/LLama.Examples/Program.cs @@ -1,4 +1,4 @@ -using LLama.Examples.NewVersion; +using LLama.Examples.Examples; using LLama.Native; Console.WriteLine("======================================================================================================"); @@ -12,4 +12,4 @@ NativeApi.llama_empty_call(); Console.WriteLine(); -await NewVersionTestRunner.Run(); \ No newline at end of file +await Runner.Run(); \ No newline at end of file