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.

StreamingTextDecoderTests.cs 1.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Text;
  2. using LLama.Common;
  3. using Xunit.Abstractions;
  4. namespace LLama.Unittest;
  5. public class StreamingTextDecoderTests
  6. : IDisposable
  7. {
  8. private readonly LLamaWeights _model;
  9. private readonly ITestOutputHelper _testOutputHelper;
  10. private readonly ModelParams _params;
  11. public StreamingTextDecoderTests(ITestOutputHelper testOutputHelper)
  12. {
  13. _testOutputHelper = testOutputHelper;
  14. _params = new ModelParams(Constants.ModelPath);
  15. _model = LLamaWeights.LoadFromFile(_params);
  16. }
  17. public void Dispose()
  18. {
  19. _model.Dispose();
  20. }
  21. [Fact]
  22. public void DecodesSimpleText()
  23. {
  24. var decoder = new StreamingTokenDecoder(Encoding.UTF8, _model);
  25. const string text = "The cat sat on the mat";
  26. var tokens = _model.NativeHandle.Tokenize(text, false, false, Encoding.UTF8);
  27. foreach (var lLamaToken in tokens)
  28. decoder.Add(lLamaToken);
  29. Assert.Equal(text, decoder.Read().Trim());
  30. }
  31. [Fact]
  32. public void DecodesComplexText()
  33. {
  34. var decoder = new StreamingTokenDecoder(Encoding.UTF8, _model);
  35. const string text = "猫坐在垫子上 😀🤨🤐😏";
  36. var tokens = _model.NativeHandle.Tokenize(text, false, false, Encoding.UTF8);
  37. foreach (var lLamaToken in tokens)
  38. decoder.Add(lLamaToken);
  39. Assert.Equal(text, decoder.Read().Trim());
  40. }
  41. }