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.

DefaultGenerationControl.cs 1.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using LLama.Abstractions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace LLama.Control
  6. {
  7. /// <summary>
  8. /// The default generation control in LLamaSharp, using antiprompts. This class should not be inherited.
  9. /// <b>Note that this class has state. The previous outputs feeded to it will affect its control.</b>
  10. /// If you use it in a session, please don't reuse it for another session unless you intend to do so.
  11. /// </summary>
  12. public sealed class DefaultGenerationControl: IGenerationControl
  13. {
  14. private AntipromptProcessor _antipromptProcessor;
  15. /// <summary>
  16. /// <inheritdoc/>
  17. /// </summary>
  18. public DefaultGenerationControl()
  19. {
  20. _antipromptProcessor = new AntipromptProcessor();
  21. }
  22. /// <summary>
  23. /// <inheritdoc/>
  24. /// </summary>
  25. public bool ShouldStopGeneration(LLamaContext context, IInferenceParams inferenceParams, string lastOutputText)
  26. {
  27. _antipromptProcessor.SetAntiprompts(inferenceParams.AntiPrompts);
  28. return _antipromptProcessor.Add(lastOutputText);
  29. }
  30. /// <summary>
  31. /// <inheritdoc/>
  32. /// </summary>
  33. public bool ShouldStopGeneration(LLamaContext context, IInferenceParams inferenceParams, IEnumerable<int> lastOutputIds)
  34. {
  35. return false;
  36. }
  37. }
  38. }