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.

ExampleRunner.cs 2.4 kB

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