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.5 kB

12345678910111213141516171819202122232425262728293031323334353637
  1. using LLama.Common;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace LLama.Examples.NewVersion
  8. {
  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. }