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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using LLama.Common;
  2. using LLama.Examples.Extensions;
  3. namespace LLama.Examples.NewVersion
  4. {
  5. public class StatelessModeExecute
  6. {
  7. public static async Task Run()
  8. {
  9. Console.Write("Please input your model path: ");
  10. var modelPath = Console.ReadLine();
  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. var ex = new StatelessExecutor(model, parameters);
  19. Console.ForegroundColor = ConsoleColor.Yellow;
  20. 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 " +
  21. "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. " +
  22. "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 " +
  23. "a prompt for it yourself!");
  24. Console.ForegroundColor = ConsoleColor.White;
  25. var inferenceParams = new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "Question:", "#", "Question: ", ".\n" }, MaxTokens = 50 };
  26. while (true)
  27. {
  28. Console.Write("\nQuestion: ");
  29. Console.ForegroundColor = ConsoleColor.Green;
  30. var prompt = Console.ReadLine();
  31. Console.ForegroundColor = ConsoleColor.White;
  32. Console.Write("Answer: ");
  33. prompt = $"Question: {prompt?.Trim()} Answer: ";
  34. await foreach (var text in ex.InferAsync(prompt, inferenceParams).Spinner())
  35. {
  36. Console.Write(text);
  37. }
  38. }
  39. }
  40. }
  41. }