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

123456789101112131415161718192021222324252627282930313233343536
  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. Console.ForegroundColor = ConsoleColor.White;
  26. var outputs = _session.Chat(question);
  27. foreach (var output in outputs)
  28. {
  29. Console.Write(output);
  30. }
  31. }
  32. }
  33. }
  34. }

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