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.

InstructModeExecute.cs 1.5 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637
  1. using LLama.Common;
  2. namespace LLama.Examples.NewVersion
  3. {
  4. public class InstructModeExecute
  5. {
  6. public static void Run()
  7. {
  8. Console.Write("Please input your model path: ");
  9. var modelPath = Console.ReadLine();
  10. var prompt = File.ReadAllText("Assets/dan.txt").Trim();
  11. var parameters = new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5);
  12. using var model = LLamaWeights.LoadFromFile(parameters);
  13. using var context = model.CreateContext(parameters);
  14. var executor = new InstructExecutor(context);
  15. Console.ForegroundColor = ConsoleColor.Yellow;
  16. Console.WriteLine("The executor has been enabled. In this example, the LLM will follow your instructions. For example, you can input \"Write a story about a fox who want to " +
  17. "make friend with human, no less than 200 words.\"");
  18. Console.ForegroundColor = ConsoleColor.White;
  19. var inferenceParams = new InferenceParams() { Temperature = 0.8f, MaxTokens = 600 };
  20. while (true)
  21. {
  22. foreach (var text in executor.Infer(prompt, inferenceParams))
  23. {
  24. Console.Write(text);
  25. }
  26. Console.ForegroundColor = ConsoleColor.Green;
  27. prompt = Console.ReadLine();
  28. Console.ForegroundColor = ConsoleColor.White;
  29. }
  30. }
  31. }
  32. }