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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Interactive executor - basic
  2. ```cs
  3. using LLama.Common;
  4. namespace LLama.Examples.Examples
  5. {
  6. // This is an example which shows how to chat with LLM with InteractiveExecutor.
  7. public class InteractiveModeExecute
  8. {
  9. public static async Task Run()
  10. {
  11. string modelPath = UserSettings.GetModelPath();
  12. var prompt = (await File.ReadAllTextAsync("Assets/chat-with-bob.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 ex = new InteractiveExecutor(context);
  22. Console.ForegroundColor = ConsoleColor.Yellow;
  23. 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)");
  24. Console.ForegroundColor = ConsoleColor.White;
  25. Console.Write(prompt);
  26. var inferenceParams = new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "User:" }, MaxTokens = 128 };
  27. while (true)
  28. {
  29. await foreach (var text in ex.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. ```