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

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Use chat session and strip role names
  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 ChatSessionStripRoleName
  10. {
  11. public static void Run()
  12. {
  13. Console.Write("Please input your model path: ");
  14. string modelPath = Console.ReadLine();
  15. var prompt = File.ReadAllText("Assets/chat-with-bob.txt").Trim();
  16. InteractiveExecutor ex = new(new LLamaModel(new ModelParams(modelPath, contextSize: 1024, seed: 1337, gpuLayerCount: 5)));
  17. ChatSession session = new ChatSession(ex).WithOutputTransform(new LLamaTransforms.KeywordTextOutputStreamTransform(new string[] { "User:", "Bob:" }, redundancyLength: 8));
  18. Console.ForegroundColor = ConsoleColor.Yellow;
  19. Console.WriteLine("The chat session has started. The role names won't be printed.");
  20. Console.ForegroundColor = ConsoleColor.White;
  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. ```