-
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.
tools: Improvements to stripping and code collection, add a token cou…
…nting bin script (#37) * tools.stripping.stripJava and tools.collectGithubRepo improvements * lint * stripping: support striping java diffs, * Add a new GPT-4 tokenizer CLI tool * update readme * Update README.md
- Loading branch information
1 parent
f4840f6
commit 41d49fb
Showing
7 changed files
with
187 additions
and
27 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
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,39 @@ | ||
#!/usr/bin/env node | ||
const gpt4 = require('gpt-tokenizer/cjs/model/gpt-4') | ||
|
||
function countTokens (text) { | ||
return gpt4.encode(text).length | ||
} | ||
|
||
function raise (msg) { | ||
if (msg) console.error(msg) | ||
console.error('Usage: langxlang <command> ...args') | ||
console.error('Usage: langxlang count <tokenizer> <file>') | ||
console.error('Example: langxlang count gpt4 myfile.js') | ||
} | ||
|
||
if (process.argv.length < 3) { | ||
raise() | ||
process.exit(1) | ||
} | ||
|
||
const commands = { | ||
count (tokenizer, file) { | ||
if (!tokenizer || !file) { | ||
raise('Must supply both a tokenizer (like gpt4) and a file') | ||
process.exit(1) | ||
} | ||
console.log('Counting tokens in', file, 'using', tokenizer) | ||
if (tokenizer === 'gpt4') { | ||
const text = require('fs').readFileSync(file, 'utf8') | ||
console.log('Tokens:', countTokens(text).toLocaleString()) | ||
} else { | ||
console.error('Unknown tokenizer', tokenizer) | ||
process.exit(1) | ||
} | ||
} | ||
} | ||
|
||
const [, , command, ...args] = process.argv | ||
console.error(`command: ${command}`, args) | ||
commands[command](...args) |
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