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

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