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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. { "Exit", () => { Environment.Exit(0); return Task.CompletedTask; } }
  32. };
  33. public static async Task Run()
  34. {
  35. AnsiConsole.Write(new Rule("LLamaSharp Examples"));
  36. while (true)
  37. {
  38. var choice = AnsiConsole.Prompt(
  39. new SelectionPrompt<string>()
  40. .Title("Please choose[green] an example[/] to run: ")
  41. .AddChoices(Examples.Keys));
  42. if (Examples.TryGetValue(choice, out var example))
  43. {
  44. AnsiConsole.Write(new Rule(choice));
  45. await example();
  46. }
  47. AnsiConsole.Reset();
  48. AnsiConsole.MarkupLine("Press ENTER to go to the main menu...");
  49. Console.ReadLine();
  50. AnsiConsole.Clear();
  51. }
  52. }
  53. }