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
12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. 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. }