You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Runner.cs 2.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Spectre.Console;
  2. namespace LLama.Examples.Examples;
  3. public class Runner
  4. {
  5. private static readonly Dictionary<string, Func<Task>> Examples = new()
  6. {
  7. { "Run a chat session without stripping the role names.", ChatSessionWithRoleName.Run },
  8. { "Run a chat session with the role names stripped.", ChatSessionStripRoleName.Run },
  9. { "Interactive mode chat by using executor.", InteractiveModeExecute.Run },
  10. { "Instruct mode chat by using executor.", InstructModeExecute.Run },
  11. { "Stateless mode chat by using executor.", StatelessModeExecute.Run },
  12. { "Load and save chat session.", SaveAndLoadSession.Run },
  13. { "Load and save state of model and executor.", LoadAndSaveState.Run },
  14. { "Get embeddings from LLama model.", () => Task.Run(GetEmbeddings.Run) },
  15. { "Quantize the model.", () => Task.Run(QuantizeModel.Run) },
  16. { "Automatic conversation.", TalkToYourself.Run },
  17. { "Constrain response to json format using grammar.", GrammarJsonResponse.Run },
  18. { "Semantic Kernel Prompt.", SemanticKernelPrompt.Run },
  19. { "Semantic Kernel Chat.", SemanticKernelChat.Run },
  20. { "Semantic Kernel Memory.", SemanticKernelMemory.Run },
  21. { "Coding Assistant.", CodingAssistant.Run },
  22. { "Batch Decoding.", BatchedDecoding.Run },
  23. { "SK Kernel Memory.", KernelMemory.Run },
  24. { "Exit", async () => Environment.Exit(0) }
  25. };
  26. public static async Task Run()
  27. {
  28. AnsiConsole.Write(new Rule("LLamaSharp Examples"));
  29. while (true)
  30. {
  31. var choice = AnsiConsole.Prompt(
  32. new SelectionPrompt<string>()
  33. .Title("Please choose[green] an example[/] to run: ")
  34. .AddChoices(Examples.Keys));
  35. if (Examples.TryGetValue(choice, out var example))
  36. {
  37. AnsiConsole.Write(new Rule(choice));
  38. await example();
  39. }
  40. AnsiConsole.Clear();
  41. }
  42. }
  43. }