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

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using LLama.Common;
  2. namespace LLama.Examples.NewVersion
  3. {
  4. public class InstructModeExecute
  5. {
  6. public static async Task 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)
  12. {
  13. ContextSize = 1024,
  14. Seed = 1337,
  15. GpuLayerCount = 5
  16. };
  17. using var model = LLamaWeights.LoadFromFile(parameters);
  18. using var context = model.CreateContext(parameters);
  19. var executor = new InstructExecutor(context);
  20. Console.ForegroundColor = ConsoleColor.Yellow;
  21. 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 " +
  22. "make friend with human, no less than 200 words.\"");
  23. Console.ForegroundColor = ConsoleColor.White;
  24. var inferenceParams = new InferenceParams() { Temperature = 0.8f, MaxTokens = 600 };
  25. while (true)
  26. {
  27. await foreach (var text in executor.InferAsync(prompt, inferenceParams))
  28. {
  29. Console.Write(text);
  30. }
  31. Console.ForegroundColor = ConsoleColor.Green;
  32. prompt = Console.ReadLine();
  33. Console.ForegroundColor = ConsoleColor.White;
  34. }
  35. }
  36. }
  37. }