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

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