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.

ChatSessionStripRoleName.cs 1.6 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839
  1. using LLama.Common;
  2. namespace LLama.Examples.NewVersion
  3. {
  4. public class ChatSessionStripRoleName
  5. {
  6. public static void Run()
  7. {
  8. Console.Write("Please input your model path: ");
  9. var modelPath = Console.ReadLine();
  10. var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim();
  11. var parameters = new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5);
  12. using var model = LLamaWeights.LoadFromFile(parameters);
  13. using var context = model.CreateContext(parameters);
  14. var executor = new InteractiveExecutor(context);
  15. var session = new ChatSession(executor).WithOutputTransform(new LLamaTransforms.KeywordTextOutputStreamTransform(new string[] { "User:", "Bob:" }, redundancyLength: 8));
  16. Console.ForegroundColor = ConsoleColor.Yellow;
  17. Console.WriteLine("The chat session has started. The role names won't be printed.");
  18. Console.ForegroundColor = ConsoleColor.White;
  19. // show the prompt
  20. Console.Write(prompt);
  21. while (true)
  22. {
  23. foreach (var text in session.Chat(prompt, new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "User:" } }))
  24. {
  25. Console.Write(text);
  26. }
  27. Console.ForegroundColor = ConsoleColor.Green;
  28. prompt = Console.ReadLine();
  29. Console.ForegroundColor = ConsoleColor.White;
  30. }
  31. }
  32. }
  33. }