forked from yamadashy/repomix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Add token counts for CLI outputs
- Loading branch information
1 parent
9ba239e
commit cc45bdd
Showing
7 changed files
with
84 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { expect, test, describe, beforeAll, afterAll } from 'vitest'; | ||
import { Tiktoken, get_encoding } from 'tiktoken'; | ||
|
||
describe('tiktoken', () => { | ||
let encoding: Tiktoken; | ||
|
||
beforeAll(() => { | ||
encoding = get_encoding('cl100k_base'); | ||
}); | ||
|
||
afterAll(() => { | ||
encoding.free(); | ||
}); | ||
|
||
test('should correctly count tokens', () => { | ||
const testCases = [ | ||
{ input: 'Hello, world!', expectedTokens: 4 }, | ||
{ input: 'This is a longer sentence with more tokens.', expectedTokens: 9 }, | ||
{ input: 'Special characters like !@#$%^&*() should be handled correctly.', expectedTokens: 15 }, | ||
{ input: 'Numbers 123 and symbols @#$ might affect tokenization.', expectedTokens: 12 }, | ||
{ input: 'Multi-line\ntext\nshould\nwork\ntoo.', expectedTokens: 11 }, | ||
]; | ||
|
||
testCases.forEach(({ input, expectedTokens }) => { | ||
const tokenCount = encoding.encode(input).length; | ||
expect(tokenCount).toBe(expectedTokens); | ||
}); | ||
}); | ||
|
||
test('should handle empty input', () => { | ||
const tokenCount = encoding.encode('').length; | ||
expect(tokenCount).toBe(0); | ||
}); | ||
|
||
test('should handle very long input', () => { | ||
const longText = 'a'.repeat(1000); | ||
const tokenCount = encoding.encode(longText).length; | ||
expect(tokenCount).toBeGreaterThan(0); | ||
}); | ||
}); |