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.

ChatService.cs 940 B

2 years ago
123456789101112131415161718192021222324252627282930313233
  1. using LLama.WebAPI.Models;
  2. namespace LLama.WebAPI.Services;
  3. public class ChatService
  4. {
  5. private readonly ChatSession<LLamaModel> _session;
  6. public ChatService()
  7. {
  8. LLamaModel model = new(new LLamaParams(model: @"ggml-model-q4_0.bin", n_ctx: 512, interactive: true, repeat_penalty: 1.0f, verbose_prompt: false));
  9. _session = new ChatSession<LLamaModel>(model)
  10. .WithPromptFile(@"Assets\chat-with-bob.txt")
  11. .WithAntiprompt(new string[] { "User:" });
  12. }
  13. public string Send(SendMessageInput input)
  14. {
  15. Console.ForegroundColor = ConsoleColor.Green;
  16. Console.WriteLine(input.Text);
  17. Console.ForegroundColor = ConsoleColor.White;
  18. var outputs = _session.Chat(input.Text);
  19. var result = "";
  20. foreach (var output in outputs)
  21. {
  22. Console.Write(output);
  23. result += output;
  24. }
  25. return result;
  26. }
  27. }

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