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.

ChatSession.cs 1.2 kB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace LLama.Examples
  7. {
  8. public class ChatSession
  9. {
  10. ChatSession<LLamaModel> _session;
  11. public ChatSession(string modelPath, string promptFilePath, string[] antiprompt)
  12. {
  13. LLamaModel model = new(new LLamaParams(model: modelPath, n_ctx: 512, interactive: true, repeat_penalty: 1.0f, verbose_prompt: false));
  14. _session = new ChatSession<LLamaModel>(model)
  15. .WithPromptFile(promptFilePath)
  16. .WithAntiprompt(antiprompt);
  17. }
  18. public void Run()
  19. {
  20. Console.Write("\nUser:");
  21. while (true)
  22. {
  23. Console.ForegroundColor = ConsoleColor.Green;
  24. var question = Console.ReadLine();
  25. question += "\n";
  26. Console.ForegroundColor = ConsoleColor.White;
  27. var outputs = _session.Chat(question, encoding: "UTF-8");
  28. foreach (var output in outputs)
  29. {
  30. Console.Write(output);
  31. }
  32. }
  33. }
  34. }
  35. }

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