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

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

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