GPT 4 Turbo-powered API documentation generator
npm install gptdocwriternpm i -g gptdocwriter
gptdocwriter --apiKey sk-abcdefg
gptdocwriter --initialFiles [index.js,utils.js] --extensions [.js,.jsx] --excluded [dist,node_modules] --model gpt-4-1106-preview
bash
Set the API key for OpenAI services
gptdocwriter --apiKey sk-abcdefg
Alternatively
gptdocwriter apiKey=sk-abcdefg
#defaults to current working directory
gptdocwriter --entryPoint path/to/src
Generate documentation for specific files before crawling extensions in the order they appear
gptdocwriter --initialFiles [utils.js,gptdocument.js]
Exclude files or directories from being documented
gptdocwriter --excluded [server.js,node_modules,dist]
Specify which file extensions to include in the documentation
gptdocwriter --extensions [js,ts,tsx,jsx]
Choose the GPT-4 model variant to use. We are rate limiting for the latest preview for you.
gptdocwriter --model gpt-4-turbo-1106
Clear current assistant before/after generating documentation (will be cleared if instructions are updated)
gptdocwriter --cleanup
Restart the thread at the last file read. Do this after a crash if you want to recover your position in the last thread, else it will be deleted on next call
gptdocwriter --continue
Tailor the prompt for the AI instead of the default prompt
gptdocwriter --instructions Write detailed documentation about each file
Include additional specific instructions
gptdocwriter --extraInstructions Mention the CLI input arguments
Specify the project name within the readme
gptdocwriter --name gptdocwriter
Change the output format to another extension than .md, e.g. we could transpose files from one programming language to another
gptdocwriter --outputFormat .py
Adjust the readme content template
gptdocwriter --readme Summarize this in a digestible format for folks who got a D in English
Rate Limit requests (default 12.5sec for GPT 4 preview, change as necessary, we'll adapt too as rate limits are uncapped)
gptdocwriter --rateLimit 20
Don't clear the thread at the end (default false else it would keep context on the next folder)
gptdocwriter --keepThread
`
!cap
Or set in utils.js and execute this locally via node gptdocument.js xxx
Or module usage:
`js
import {generateDocumentation} from 'gptdocwriter'
// CLI usage to call generateDocumentation
generateDocumentation(
process.cwd(),
['utils.js'], //scan the rest of the files after this specified order is completed
['.js', '.ts', '.mjs', '.jsx', '.tsx'],
['dist','node_modules']
);
`
The prompt for all of this is experimental so tweak it as you need. Results can vary wildly though we tried to make it consistent enough to be passable, but you will need to edit your files afterward (which you should be doing anyway for serious documentation, this only provides an enhanced template).
See a repo where I applied this to a fairly hefty codebase: JS Maze Generator with A* solver
$3
- Generated with: node gptdocument.js --excluded server.js,node_modules,dist --initialFiles package.json,utils.js --cleanup --extraInstructions Write EVERYTHING in iambic pentameter verse without exception.
GPT Doc Writer 📜✍️
In lands of code where silence reigns,
The GPT Doc Writer deigns,
To turn the tide of documentation's chore,
Into an art, less bore, more lore.
Quick Start 🚀
To weave the magic of this script's employ,
Ensure to set the API deploy.
Run commands below, command line's your stage,
To document your code, turn a new page.
`bash
gptdocwriter --apiKey YOUR_API_KEY
gptdocwriter --entryPoint path/to/src --initialFiles utils.js,gptdocument.js
...and any other options you wish to engage
`
Installation 🛠
In terminal's embrace, these words recite,
And lo, the GPT Doc Writer takes flight:
`bash
npm install -g gptdocwriter
or, for the bards who seek yonder ridge:
yarn add gptdocwriter
`
Usage 📖
Invoke with args that you understand,
From where to start, what files to demand.
Exclude, include, with precision's touch,
And see how well it documents much.
Documentation Directory 🗂
Herein the structure, clear and deft,
With markdown files, right and left:
- ./documentation/utils.js.md: Tools to map and glow,
CLI args and configs, oh, do they flow!
- ./documentation/console.js.md: Colors to command, woesome console to tame,
A parser of args, all in the game.
Use Cases 🎯
- In times of rush, when docs are drear,
This tool comes forth to lend an ear.
- For projects vast as the sea's own realm,
GPT Doc Writer takes the helm.
- And should you wish to transit code,
To another language, to lighten the load,
With output formats, it strides in stride,
From .js to .py`, worlds do collide.