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

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Use stateless executor
  2. ```cs
  3. using LLama.Common;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. public class StatelessModeExecute
  10. {
  11. public static void Run()
  12. {
  13. Console.Write("Please input your model path: ");
  14. string modelPath = Console.ReadLine();
  15. StatelessExecutor ex = new(new LLamaModel(new ModelParams(modelPath, contextSize: 256)));
  16. Console.ForegroundColor = ConsoleColor.Yellow;
  17. 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 " +
  18. "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. " +
  19. "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 " +
  20. "a prompt for it yourself!");
  21. Console.ForegroundColor = ConsoleColor.White;
  22. var inferenceParams = new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "Question:", "#", "Question: ", ".\n" }, MaxTokens = 50 };
  23. while (true)
  24. {
  25. Console.Write("\nQuestion: ");
  26. Console.ForegroundColor = ConsoleColor.Green;
  27. string prompt = Console.ReadLine();
  28. Console.ForegroundColor = ConsoleColor.White;
  29. Console.Write("Answer: ");
  30. prompt = $"Question: {prompt.Trim()} Answer: ";
  31. foreach (var text in ex.Infer(prompt, inferenceParams))
  32. {
  33. Console.Write(text);
  34. }
  35. }
  36. }
  37. }
  38. ```