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.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. { "Chinese gb2312 chat", ChatChineseGB2312.Run },
  25. { "Exit", async () => Environment.Exit(0) }
  26. };
  27. public static async Task Run()
  28. {
  29. AnsiConsole.Write(new Rule("LLamaSharp Examples"));
  30. while (true)
  31. {
  32. var choice = AnsiConsole.Prompt(
  33. new SelectionPrompt<string>()
  34. .Title("Please choose[green] an example[/] to run: ")
  35. .AddChoices(Examples.Keys));
  36. if (Examples.TryGetValue(choice, out var example))
  37. {
  38. AnsiConsole.Write(new Rule(choice));
  39. await example();
  40. }
  41. Console.WriteLine("Press any key to continue...");
  42. Console.ReadKey();
  43. AnsiConsole.Clear();
  44. }
  45. }
  46. }