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.

Program.cs 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using LLama;
  2. using LLama.Common;
  3. using LLama.Examples;
  4. Console.WriteLine("======================================================================================================");
  5. Console.WriteLine(" __ __ ____ __ \r\n/\\ \\ /\\ \\ /\\ _`\\ /\\ \\ \r\n\\ \\ \\ \\ \\ \\ __ ___ ___ __ \\ \\,\\L\\_\\\\ \\ \\___ __ _ __ _____ \r\n \\ \\ \\ __\\ \\ \\ __ /'__`\\ /' __` __`\\ /'__`\\ \\/_\\__ \\ \\ \\ _ `\\ /'__`\\ /\\`'__\\/\\ '__`\\ \r\n \\ \\ \\L\\ \\\\ \\ \\L\\ \\/\\ \\L\\.\\_ /\\ \\/\\ \\/\\ \\ /\\ \\L\\.\\_ /\\ \\L\\ \\\\ \\ \\ \\ \\ /\\ \\L\\.\\_\\ \\ \\/ \\ \\ \\L\\ \\\r\n \\ \\____/ \\ \\____/\\ \\__/.\\_\\\\ \\_\\ \\_\\ \\_\\\\ \\__/.\\_\\\\ `\\____\\\\ \\_\\ \\_\\\\ \\__/.\\_\\\\ \\_\\ \\ \\ ,__/\r\n \\/___/ \\/___/ \\/__/\\/_/ \\/_/\\/_/\\/_/ \\/__/\\/_/ \\/_____/ \\/_/\\/_/ \\/__/\\/_/ \\/_/ \\ \\ \\/ \r\n \\ \\_\\ \r\n \\/_/ ");
  6. Console.WriteLine("======================================================================================================");
  7. Console.WriteLine();
  8. Console.WriteLine("Please choose the version you want to test: ");
  9. Console.WriteLine("0. old version (for v0.3.0 or earlier version)");
  10. Console.WriteLine("1. new version (for versions after v0.4.0)");
  11. Console.Write("\nYour Choice: ");
  12. int version = int.Parse(Console.ReadLine());
  13. Console.WriteLine();
  14. if(version == 1)
  15. {
  16. Console.WriteLine("The examples for new versions are under working now. We'll soon update the examples." +
  17. " Thank you for your support!");
  18. string modelPath = "D:\\development\\llama\\weights\\wizard-vicuna-13B.ggmlv3.q4_1.bin";
  19. var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim();
  20. //string prompt = " Qeustion: how to do binary search for an array in C#? Answer: ";
  21. InteractiveExecutor ex = new(new LLamaModel(new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5)));
  22. ChatSession session = new ChatSession(ex).WithOutputTransform(new LLamaTransforms.KeywordTextOutputStreamTransform(new string[] { "User:", "Bob:" }));
  23. while (prompt != "skip")
  24. {
  25. await foreach (var text in session.ChatAsync(prompt, new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "User:" } }, default(CancellationToken)))
  26. {
  27. Console.Write(text);
  28. }
  29. prompt = Console.ReadLine();
  30. if(prompt == "save")
  31. {
  32. session.SaveSession("./SessionState");
  33. Console.WriteLine("Saved session!");
  34. ex.Model.Dispose();
  35. ex = new(new LLamaModel(new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5)));
  36. session = new ChatSession(ex).WithOutputTransform(new LLamaTransforms.KeywordTextOutputStreamTransform(new string[] { "User:", "Bob:" }));
  37. session.LoadSession("./SessionState");
  38. Console.WriteLine("Loaded session!");
  39. prompt = Console.ReadLine();
  40. }
  41. }
  42. ex.Model.Dispose();
  43. //StatelessExecutor ex = new(new LLamaModel(new ModelParams(modelPath, contextSize: 256)));
  44. //while (true)
  45. //{
  46. // foreach (var text in ex.Infer(prompt, new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "user:" }, MaxTokens = 256 }))
  47. // {
  48. // Console.Write(text);
  49. // }
  50. // prompt = Console.ReadLine();
  51. //}
  52. //LLama.Examples.NewVersion.SaveAndLoadState runner = new(modelPath, prompt);
  53. //while (true)
  54. //{
  55. // var input = Console.ReadLine();
  56. // if(input == "save")
  57. // {
  58. // Console.Write("Your path to save state: ");
  59. // input = Console.ReadLine();
  60. // runner.SaveState("./ex_state.json", input);
  61. // runner.LoadState("./ex_state.json", input);
  62. // }
  63. // else
  64. // {
  65. // runner.Run(input);
  66. // }
  67. //}
  68. }
  69. else
  70. {
  71. LLama.Examples.Old.OldTestRunner.Run();
  72. }

C#/.NET上易用的LLM高性能推理框架,支持LLaMA和LLaVA系列模型。