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 957 B

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

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