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.Examples
  3. {
  4. // This example shows how to use InstructExecutor to generate the response.
  5. public class InstructModeExecute
  6. {
  7. public static async Task Run()
  8. {
  9. string modelPath = UserSettings.GetModelPath();
  10. var prompt = File.ReadAllText("Assets/dan.txt").Trim();
  11. var parameters = new ModelParams(modelPath)
  12. {
  13. Seed = 1337,
  14. GpuLayerCount = 5
  15. };
  16. using var model = LLamaWeights.LoadFromFile(parameters);
  17. using var context = model.CreateContext(parameters);
  18. var executor = new InstructExecutor(context);
  19. Console.ForegroundColor = ConsoleColor.Yellow;
  20. 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 " +
  21. "make friend with human, no less than 200 words.\"");
  22. Console.ForegroundColor = ConsoleColor.White;
  23. var inferenceParams = new InferenceParams() { Temperature = 0.8f, MaxTokens = 600 };
  24. while (true)
  25. {
  26. await foreach (var text in executor.InferAsync(prompt, inferenceParams))
  27. {
  28. Console.Write(text);
  29. }
  30. Console.ForegroundColor = ConsoleColor.Green;
  31. prompt = Console.ReadLine();
  32. Console.ForegroundColor = ConsoleColor.White;
  33. }
  34. }
  35. }
  36. }