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.

ChatWithLLamaModelV1.cs 1.4 kB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using LLama.Types;
  7. namespace LLama.Examples
  8. {
  9. public class ChatWithLLamaModelV1
  10. {
  11. LLamaModelV1 _model;
  12. public ChatWithLLamaModelV1(string modelPath)
  13. {
  14. _model = new(modelPath, logits_all: false, verbose: false, n_ctx: 512);
  15. }
  16. public void Run()
  17. {
  18. List<ChatCompletionMessage> chats = new List<ChatCompletionMessage>();
  19. chats.Add(new ChatCompletionMessage(ChatRole.Human, "Hi, Alice, I'm Rinne."));
  20. chats.Add(new ChatCompletionMessage(ChatRole.Assistant, "Hi, Rinne, I'm Alice, an assistant that answer any question. What can I do for you?"));
  21. while (true)
  22. {
  23. Console.Write("\nYou: ");
  24. Console.ForegroundColor = ConsoleColor.Green;
  25. var question = Console.ReadLine();
  26. Console.ForegroundColor = ConsoleColor.White;
  27. chats.Add(new ChatCompletionMessage(ChatRole.Human, question));
  28. var outputs = _model.CreateChatCompletion(chats, max_tokens: 256);
  29. Console.Write($"LLama AI: ");
  30. foreach (var output in outputs)
  31. {
  32. Console.Write($"{output.Choices[0].Delta.Content}");
  33. }
  34. }
  35. }
  36. }
  37. }

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