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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using LLama.Types;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Text;
  6. namespace LLama
  7. {
  8. public class ChatSession<T> where T: IChatModel
  9. {
  10. IChatModel _model;
  11. List<ChatMessageRecord> History { get; } = new List<ChatMessageRecord>();
  12. public ChatSession(T model)
  13. {
  14. _model = model;
  15. }
  16. public IEnumerable<string> Chat(string text, string? prompt = null)
  17. {
  18. return _model.Chat(text, prompt);
  19. }
  20. public ChatSession<T> WithPrompt(string prompt)
  21. {
  22. _model.InitChatPrompt(prompt);
  23. return this;
  24. }
  25. public ChatSession<T> WithPromptFile(string promptFilename)
  26. {
  27. return WithPrompt(File.ReadAllText(promptFilename));
  28. }
  29. /// <summary>
  30. /// Set the keyword to split the return value of chat AI.
  31. /// </summary>
  32. /// <param name="humanName"></param>
  33. /// <returns></returns>
  34. public ChatSession<T> WithAntiprompt(string[] antiprompt)
  35. {
  36. _model.InitChatAntiprompt(antiprompt);
  37. return this;
  38. }
  39. }
  40. }

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