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

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using LLama.Common;
  2. namespace LLama.Examples.NewVersion
  3. {
  4. public class ChatSessionWithRoleName
  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)
  12. {
  13. ContextSize = 1024,
  14. Seed = 1337,
  15. GpuLayerCount = 5
  16. };
  17. using var model = LLamaWeights.LoadFromFile(parameters);
  18. using var context = model.CreateContext(parameters);
  19. var executor = new InteractiveExecutor(context);
  20. var session = new ChatSession(executor);
  21. Console.ForegroundColor = ConsoleColor.Yellow;
  22. Console.WriteLine("The chat session has started. In this example, the prompt is printed for better visual result.");
  23. Console.ForegroundColor = ConsoleColor.White;
  24. // show the prompt
  25. Console.Write(prompt);
  26. while (true)
  27. {
  28. foreach (var text in session.Chat(prompt, new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "User:" } }))
  29. {
  30. Console.Write(text);
  31. }
  32. Console.ForegroundColor = ConsoleColor.Green;
  33. prompt = Console.ReadLine();
  34. Console.ForegroundColor = ConsoleColor.White;
  35. }
  36. }
  37. }
  38. }