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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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: Save/Load", BatchedExecutorSaveAndLoad.Run },
  29. { "Batched Executor: Fork", BatchedExecutorFork.Run },
  30. { "Batched Executor: Rewind", BatchedExecutorRewind.Run },
  31. { "Batched Executor: Guidance", BatchedExecutorGuidance.Run },
  32. { "Speech Chat: Integration with Whisper.net", SpeechChat.Run },
  33. { "Exit", () => { Environment.Exit(0); return Task.CompletedTask; } }
  34. };
  35. public static async Task Run()
  36. {
  37. AnsiConsole.Write(new Rule("LLamaSharp Examples"));
  38. while (true)
  39. {
  40. var choice = AnsiConsole.Prompt(
  41. new SelectionPrompt<string>()
  42. .Title("Please choose[green] an example[/] to run: ")
  43. .AddChoices(Examples.Keys));
  44. if (Examples.TryGetValue(choice, out var example))
  45. {
  46. AnsiConsole.Write(new Rule(choice));
  47. await example();
  48. }
  49. AnsiConsole.Reset();
  50. AnsiConsole.MarkupLine("Press ENTER to go to the main menu...");
  51. Console.ReadLine();
  52. AnsiConsole.Clear();
  53. }
  54. }
  55. }