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.

Extensions.cs 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using LLama.Web.Common;
  2. namespace LLama.Web
  3. {
  4. public static class Extensions
  5. {
  6. /// <summary>
  7. /// Combines the AntiPrompts list and AntiPrompt csv
  8. /// </summary>
  9. /// <param name="sessionConfig">The session configuration.</param>
  10. /// <returns>Combined AntiPrompts with duplicates removed</returns>
  11. public static List<string> GetAntiPrompts(this ISessionConfig sessionConfig)
  12. {
  13. return CombineCSV(sessionConfig.AntiPrompts, sessionConfig.AntiPrompt);
  14. }
  15. /// <summary>
  16. /// Combines the OutputFilters list and OutputFilter csv
  17. /// </summary>
  18. /// <param name="sessionConfig">The session configuration.</param>
  19. /// <returns>Combined OutputFilters with duplicates removed</returns>
  20. public static List<string> GetOutputFilters(this ISessionConfig sessionConfig)
  21. {
  22. return CombineCSV(sessionConfig.OutputFilters, sessionConfig.OutputFilter);
  23. }
  24. /// <summary>
  25. /// Combines a string list and a csv and removes duplicates
  26. /// </summary>
  27. /// <param name="list">The list.</param>
  28. /// <param name="csv">The CSV.</param>
  29. /// <returns>Combined list with duplicates removed</returns>
  30. private static List<string> CombineCSV(List<string> list, string csv)
  31. {
  32. var results = list?.Count == 0
  33. ? CommaSeperatedToList(csv)
  34. : CommaSeperatedToList(csv).Concat(list);
  35. return results
  36. .Distinct()
  37. .ToList();
  38. }
  39. private static List<string> CommaSeperatedToList(string value)
  40. {
  41. if (string.IsNullOrEmpty(value))
  42. return new List<string>();
  43. return value.Split(",", StringSplitOptions.RemoveEmptyEntries)
  44. .Select(x => x.Trim())
  45. .ToList();
  46. }
  47. }
  48. }