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.

TestRunner.cs 4.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace LLama.Examples.Old
  7. {
  8. public class OldTestRunner
  9. {
  10. public static void Run()
  11. {
  12. Console.WriteLine("================LLamaSharp Examples (Old Version)==================\n");
  13. Console.WriteLine("Please input a number to choose an example to run:");
  14. Console.WriteLine("0: Run a chat session.");
  15. Console.WriteLine("1: Run a LLamaModel to chat.");
  16. Console.WriteLine("2: Quantize a model.");
  17. Console.WriteLine("3: Get the embeddings of a message.");
  18. Console.WriteLine("4: Run a LLamaModel with instruct mode.");
  19. Console.WriteLine("5: Load and save state of LLamaModel.");
  20. while (true)
  21. {
  22. Console.Write("\nYour choice: ");
  23. int choice = int.Parse(Console.ReadLine());
  24. if (choice == 0)
  25. {
  26. Console.Write("Please input your model path: ");
  27. var modelPath = Console.ReadLine();
  28. ChatSession chat = new(modelPath, "Assets/chat-with-bob.txt", new string[] { "User:" });
  29. chat.Run();
  30. }
  31. else if (choice == 1)
  32. {
  33. Console.Write("Please input your model path: ");
  34. var modelPath = Console.ReadLine();
  35. ChatWithLLamaModel chat = new(modelPath, "Assets/chat-with-bob.txt", new string[] { "User:" });
  36. chat.Run();
  37. }
  38. else if (choice == 2) // quantization
  39. {
  40. Console.Write("Please input your original model path: ");
  41. var inputPath = Console.ReadLine();
  42. Console.Write("Please input your output model path: ");
  43. var outputPath = Console.ReadLine();
  44. Console.Write("Please input the quantize type (one of q4_0, q4_1, q5_0, q5_1, q8_0): ");
  45. var quantizeType = Console.ReadLine();
  46. Quantize q = new Quantize();
  47. q.Run(inputPath, outputPath, quantizeType);
  48. }
  49. else if (choice == 3) // get the embeddings only
  50. {
  51. Console.Write("Please input your model path: ");
  52. var modelPath = Console.ReadLine();
  53. GetEmbeddings em = new GetEmbeddings(modelPath);
  54. Console.Write("Please input the text: ");
  55. var text = Console.ReadLine();
  56. em.Run(text);
  57. }
  58. else if (choice == 4) // instruct mode
  59. {
  60. Console.Write("Please input your model path: ");
  61. var modelPath = Console.ReadLine();
  62. InstructMode im = new InstructMode(modelPath, "Assets/alpaca.txt");
  63. Console.WriteLine("Here's a simple example for using instruct mode. You can input some words and let AI " +
  64. "complete it for you. For example: Write a story about a fox that wants to make friend with human. No less than 200 words.");
  65. im.Run();
  66. }
  67. else if (choice == 5) // load and save state
  68. {
  69. Console.Write("Please input your model path: ");
  70. var modelPath = Console.ReadLine();
  71. Console.Write("Please input your state file path: ");
  72. var statePath = Console.ReadLine();
  73. SaveAndLoadState sals = new(modelPath, File.ReadAllText(@"D:\development\llama\llama.cpp\prompts\alpaca.txt"));
  74. sals.Run("Write a story about a fox that wants to make friend with human. No less than 200 words.");
  75. sals.SaveState(statePath);
  76. sals.Dispose();
  77. GC.Collect();
  78. GC.WaitForPendingFinalizers();
  79. // create a new model to load the state.
  80. SaveAndLoadState sals2 = new(modelPath, "");
  81. sals2.LoadState(statePath);
  82. sals2.Run("Tell me more things about the fox in the story you told me.");
  83. }
  84. else
  85. {
  86. Console.WriteLine("Cannot parse your choice. Please select again.");
  87. continue;
  88. }
  89. break;
  90. }
  91. }
  92. }
  93. }

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