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.

StatelessModeExecute.cs 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using LLama.Common;
  2. namespace LLama.Examples.NewVersion
  3. {
  4. public class StatelessModeExecute
  5. {
  6. public static void Run()
  7. {
  8. Console.Write("Please input your model path: ");
  9. var modelPath = Console.ReadLine();
  10. var parameters = new ModelParams(modelPath)
  11. {
  12. ContextSize = 1024,
  13. Seed = 1337,
  14. GpuLayerCount = 5
  15. };
  16. using var model = LLamaWeights.LoadFromFile(parameters);
  17. var ex = new StatelessExecutor(model, parameters);
  18. Console.ForegroundColor = ConsoleColor.Yellow;
  19. Console.WriteLine("The executor has been enabled. In this example, the inference is an one-time job. That says, the previous input and response has " +
  20. "no impact on the current response. Now you can ask it questions. Note that in this example, no prompt was set for LLM and the maximum response tokens is 50. " +
  21. "It may not perform well because of lack of prompt. This is also an example that could indicate the improtance of prompt in LLM. To improve it, you can add " +
  22. "a prompt for it yourself!");
  23. Console.ForegroundColor = ConsoleColor.White;
  24. var inferenceParams = new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "Question:", "#", "Question: ", ".\n" }, MaxTokens = 50 };
  25. while (true)
  26. {
  27. Console.Write("\nQuestion: ");
  28. Console.ForegroundColor = ConsoleColor.Green;
  29. var prompt = Console.ReadLine();
  30. Console.ForegroundColor = ConsoleColor.White;
  31. Console.Write("Answer: ");
  32. prompt = $"Question: {prompt?.Trim()} Answer: ";
  33. foreach (var text in ex.Infer(prompt, inferenceParams))
  34. {
  35. Console.Write(text);
  36. }
  37. }
  38. }
  39. }
  40. }