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.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.OldVersion;
  7. namespace LLama.Examples.Old
  8. {
  9. [Obsolete("The entire LLama.OldVersion namespace will be removed")]
  10. public class ChatSession
  11. {
  12. LLama.OldVersion.ChatSession<LLama.OldVersion.LLamaModel> _session;
  13. public ChatSession(string modelPath, string promptFilePath, string[] antiprompt)
  14. {
  15. LLama.OldVersion.LLamaModel model = new(new LLamaParams(model: modelPath, n_ctx: 512, interactive: true, repeat_penalty: 1.0f, verbose_prompt: false));
  16. _session = new ChatSession<LLama.OldVersion.LLamaModel>(model)
  17. .WithPromptFile(promptFilePath)
  18. .WithAntiprompt(antiprompt);
  19. }
  20. public void Run()
  21. {
  22. Console.Write("\nUser:");
  23. while (true)
  24. {
  25. Console.ForegroundColor = ConsoleColor.Green;
  26. var question = Console.ReadLine();
  27. question += "\n";
  28. Console.ForegroundColor = ConsoleColor.White;
  29. var outputs = _session.Chat(question, encoding: "UTF-8");
  30. foreach (var output in outputs)
  31. {
  32. Console.Write(output);
  33. }
  34. }
  35. }
  36. }
  37. }