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

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