LibreChat/api/app/clients/document/tokenSplit.spec.js
Danny Avila 95201908e9
📦 fix: npm warnings; chore: bump deprecated packages (#4707)
* chore: bump langchain deps to address vulnerability warnings

* chore: bump community package and install textsplitters package

* fix: update expected result in tokenSplit tests for accuracy

* chore: remove CodeSherpa tools

* chore: remove E2B tools and loadToolSuite

* chore: remove CodeBrew tool and update related references

* chore: remove HumanTool and ChatTool, update tool references

* chore: remove Zapier tool from manifest.json and update SerpAPI

* chore: remove basic tools

* chore: update import path for RecursiveCharacterTextSplitter

* chore: update import path for DynamicStructuredTool

* chore: remove extractionChain.js and update tool filtering logic

* chore: npm audit fix

* chore: bump google packages

* chore: update DALL-E tool to DALL-E-3 and adjust authentication logic

* ci: update message classes

* chore: elliptic npm audit fix

* chore: update CallbackManager import and remove deprecated tool handling logic

* chore: imports order

* chore: remove unused code

---------

Co-authored-by: Max Sanna <max@maxsanna.com>
2024-11-12 18:51:32 -05:00

56 lines
1.5 KiB
JavaScript

const tokenSplit = require('./tokenSplit');
describe('tokenSplit', () => {
const text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id.';
it('returns correct text chunks with provided parameters', async () => {
const result = await tokenSplit({
text: text,
encodingName: 'gpt2',
chunkSize: 2,
chunkOverlap: 1,
returnSize: 5,
});
expect(result).toEqual(['it.', '. Null', ' Nullam', 'am id', ' id.']);
});
it('returns correct text chunks with default parameters', async () => {
const result = await tokenSplit({ text });
expect(result).toEqual([
'Lorem',
' ipsum',
' dolor',
' sit',
' amet',
',',
' consectetur',
' adipiscing',
' elit',
'.',
' Null',
'am',
' id',
'.',
]);
});
it('returns correct text chunks with specific return size', async () => {
const result = await tokenSplit({ text, returnSize: 2 });
expect(result.length).toEqual(2);
expect(result).toEqual([' id', '.']);
});
it('returns correct text chunks with specified chunk size', async () => {
const result = await tokenSplit({ text, chunkSize: 10 });
expect(result).toEqual([
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
' Nullam id.',
]);
});
it('returns empty array with no text', async () => {
const result = await tokenSplit({ text: '' });
expect(result).toEqual([]);
});
});