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.md 1.7 kB

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