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
1234567891011121314151617181920212223242526272829303132333435363738
  1. using LLama.Common;
  2. using System.Text;
  3. namespace LLama.Examples.NewVersion
  4. {
  5. public class InstructModeExecute
  6. {
  7. public static void Run()
  8. {
  9. Console.Write("Please input your model path: ");
  10. var modelPath = Console.ReadLine();
  11. var prompt = File.ReadAllText("Assets/dan.txt").Trim();
  12. var parameters = new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5);
  13. using var model = LLamaWeights.LoadFromFile(parameters);
  14. using var context = model.CreateContext(parameters);
  15. var executor = new InstructExecutor(context);
  16. Console.ForegroundColor = ConsoleColor.Yellow;
  17. 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 " +
  18. "make friend with human, no less than 200 words.\"");
  19. Console.ForegroundColor = ConsoleColor.White;
  20. var inferenceParams = new InferenceParams() { Temperature = 0.8f, MaxTokens = 600 };
  21. while (true)
  22. {
  23. foreach (var text in executor.Infer(prompt, inferenceParams))
  24. {
  25. Console.Write(text);
  26. }
  27. Console.ForegroundColor = ConsoleColor.Green;
  28. prompt = Console.ReadLine();
  29. Console.ForegroundColor = ConsoleColor.White;
  30. }
  31. }
  32. }
  33. }