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

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Use chat session without removing 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 ChatSessionWithRoleName
  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); // The only change is to remove the transform for the output text stream.
  18. Console.ForegroundColor = ConsoleColor.Yellow;
  19. Console.WriteLine("The chat session has started. In this example, the prompt is printed for better visual result.");
  20. Console.ForegroundColor = ConsoleColor.White;
  21. // show the prompt
  22. Console.Write(prompt);
  23. while (true)
  24. {
  25. foreach (var text in session.Chat(prompt, new InferenceParams() { Temperature = 0.6f, AntiPrompts = new List<string> { "User:" } }))
  26. {
  27. Console.Write(text);
  28. }
  29. Console.ForegroundColor = ConsoleColor.Green;
  30. prompt = Console.ReadLine();
  31. Console.ForegroundColor = ConsoleColor.White;
  32. }
  33. }
  34. }
  35. ```

C#/.NET上易用的LLM高性能推理框架,支持LLaMA和LLaVA系列模型。