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.

ChatSessionWithRoleName.cs 1.5 kB

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