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.

InteractiveModeExecute.cs 1.6 kB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using LLama.Common;
  2. using System.Text;
  3. namespace LLama.Examples.NewVersion
  4. {
  5. public class InteractiveModeExecute
  6. {
  7. public static async Task Run()
  8. {
  9. Console.Write("Please input your model path: ");
  10. var modelPath = Console.ReadLine();
  11. var prompt = (await File.ReadAllTextAsync("Assets/chat-with-bob.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, Encoding.UTF8);
  15. var ex = new InteractiveExecutor(context);
  16. Console.ForegroundColor = ConsoleColor.Yellow;
  17. Console.WriteLine("The executor has been enabled. In this example, the prompt is printed, the maximum tokens is set to 128 and the context size is 256. (an example for small scale usage)");
  18. Console.ForegroundColor = ConsoleColor.White;
  19. Console.Write(prompt);
  20. var inferenceParams = new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "User:" }, MaxTokens = 128 };
  21. while (true)
  22. {
  23. await foreach (var text in ex.InferAsync(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. }