Skip to content

Commit

Permalink
Add github repo to markdown command to CLI tool
Browse files Browse the repository at this point in the history
  • Loading branch information
extremeheat committed Aug 2, 2024
1 parent 8359380 commit 81b2294
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node
const fs = require('fs')
const gpt4 = require('gpt-tokenizer/cjs/model/gpt-4')
const { CompletionService } = require('langxlang')
const { CompletionService, tools } = require('langxlang')

function countTokens (text) {
return gpt4.encode(text).length
Expand All @@ -10,8 +11,11 @@ function raise (msg) {
if (msg) console.error(msg)
console.error('Usage: langxlang <command> ...args')
console.error('Usage: langxlang count <tokenizer> <file>')
console.error('Usage: langxlang githubRepoToMarkdown <repo> <branch or ref> [output file]')
console.error('Usage (alias): langxlang repo2md <repo> <branch or ref> [output file]')
console.error('Example: langxlang count gpt4 myfile.js')
console.error('Example: langxlang count gemini1.5pro myfile.txt')
console.error('Example: langxlang githubRepoToMarkdown PrismarineJS/vec3 master vec3.md')
}

if (process.argv.length < 3) {
Expand All @@ -38,9 +42,19 @@ const commands = {
console.error('Unknown tokenizer', tokenizer)
process.exit(1)
}
},
githubRepoToMarkdown (repo, branch, outFile = 'repo.md') {
const files = tools.collectGithubRepoFiles(repo, {
branch,
truncateLargeFiles: 16_000 // 16k
})
const md = tools.concatFilesToMarkdown(files)
fs.writeFileSync(outFile, md)
}
}

commands.repo2md = commands.githubRepoToMarkdown

const [, , command, ...args] = process.argv
console.error(`command: ${command}`, args)
commands[command](...args)

0 comments on commit 81b2294

Please sign in to comment.