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.

Runner.cs 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Spectre.Console;
  2. namespace LLama.Examples.Examples;
  3. public class Runner
  4. {
  5. private static readonly Dictionary<string, Func<Task>> Examples = new()
  6. {
  7. { "Run a chat session with history.", ChatSessionWithHistory.Run },
  8. { "Run a chat session without stripping the role names.", ChatSessionWithRoleName.Run },
  9. { "Run a chat session with the role names stripped.", ChatSessionStripRoleName.Run },
  10. { "Run a chat session in Chinese GB2312 encoding", ChatChineseGB2312.Run },
  11. { "Interactive mode chat by using executor.", InteractiveModeExecute.Run },
  12. { "Instruct mode chat by using executor.", InstructModeExecute.Run },
  13. { "Stateless mode chat by using executor.", StatelessModeExecute.Run },
  14. { "Load and save chat session.", SaveAndLoadSession.Run },
  15. { "Load and save state of model and executor.", LoadAndSaveState.Run },
  16. { "Get embeddings from LLama model.", () => Task.Run(GetEmbeddings.Run) },
  17. { "Quantize the model.", () => Task.Run(QuantizeModel.Run) },
  18. { "Automatic conversation.", TalkToYourself.Run },
  19. { "Constrain response to json format using grammar.", GrammarJsonResponse.Run },
  20. { "Semantic Kernel Prompt.", SemanticKernelPrompt.Run },
  21. { "Semantic Kernel Chat.", SemanticKernelChat.Run },
  22. { "Semantic Kernel Memory.", SemanticKernelMemory.Run },
  23. { "Coding Assistant.", CodingAssistant.Run },
  24. { "Batch Decoding.", BatchedDecoding.Run },
  25. { "SK Kernel Memory.", KernelMemory.Run },
  26. { "Exit", async () => Environment.Exit(0) }
  27. };
  28. public static async Task Run()
  29. {
  30. AnsiConsole.Write(new Rule("LLamaSharp Examples"));
  31. while (true)
  32. {
  33. var choice = AnsiConsole.Prompt(
  34. new SelectionPrompt<string>()
  35. .Title("Please choose[green] an example[/] to run: ")
  36. .AddChoices(Examples.Keys));
  37. if (Examples.TryGetValue(choice, out var example))
  38. {
  39. AnsiConsole.Write(new Rule(choice));
  40. await example();
  41. }
  42. Console.WriteLine("Press any key to continue...");
  43. Console.ReadKey();
  44. AnsiConsole.Clear();
  45. }
  46. }
  47. }