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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. { "Chat Session: History", ChatSessionWithHistory.Run },
  8. { "Chat Session: Role names", ChatSessionWithRoleName.Run },
  9. { "Chat Session: Role names stripped", ChatSessionStripRoleName.Run },
  10. { "Chat Session: Coding Assistant", CodingAssistant.Run },
  11. { "Chat Session: Automatic conversation", TalkToYourself.Run },
  12. { "Chat Session: Chinese characters", ChatChineseGB2312.Run },
  13. { "Executor: Interactive mode chat", InteractiveModeExecute.Run },
  14. { "Executor: Instruct mode chat", InstructModeExecute.Run },
  15. { "Executor: Stateless mode chat", StatelessModeExecute.Run },
  16. { "Save and Load: chat session", SaveAndLoadSession.Run },
  17. { "Save and Load: state of model and executor", LoadAndSaveState.Run },
  18. { "LLama Model: Get embeddings", () => Task.Run(GetEmbeddings.Run) },
  19. { "LLama Model: Quantize", () => Task.Run(QuantizeModel.Run) },
  20. { "Grammar: Constrain response to json format", GrammarJsonResponse.Run },
  21. { "Kernel Memory: Document Q&A", KernelMemory.Run },
  22. { "Kernel Memory: Save and Load", KernelMemorySaveAndLoad.Run },
  23. { "Semantic Kernel: Prompt", SemanticKernelPrompt.Run },
  24. { "Semantic Kernel: Chat", SemanticKernelChat.Run },
  25. { "Semantic Kernel: Store", SemanticKernelMemory.Run },
  26. { "Batched Executor: Fork", BatchedExecutorFork.Run },
  27. { "Batched Executor: Rewind", BatchedExecutorRewind.Run },
  28. { "Batched Executor: Guidance", BatchedExecutorGuidance.Run },
  29. { "Exit", () => { Environment.Exit(0); return Task.CompletedTask; } }
  30. };
  31. public static async Task Run()
  32. {
  33. AnsiConsole.Write(new Rule("LLamaSharp Examples"));
  34. while (true)
  35. {
  36. var choice = AnsiConsole.Prompt(
  37. new SelectionPrompt<string>()
  38. .Title("Please choose[green] an example[/] to run: ")
  39. .AddChoices(Examples.Keys));
  40. if (Examples.TryGetValue(choice, out var example))
  41. {
  42. AnsiConsole.Write(new Rule(choice));
  43. await example();
  44. }
  45. AnsiConsole.Reset();
  46. AnsiConsole.MarkupLine("Press ENTER to go to the main menu...");
  47. Console.ReadLine();
  48. AnsiConsole.Clear();
  49. }
  50. }
  51. }