DocAi is a tool that allows you to automatically generate markdown-formatted documentation for your code.
npm install --save-dev docai
Your code will be sent to an external provider; ensure that you have the rights to do so.
To document only some files:
import docai from 'docai'
await docai({
llm: {
apiKey: 'YOUR_API_KEY'
modelProvider: 'mistral' | 'openAI' | 'groq'
modelName: 'mistral-tiny' | 'gpt-4' | ...
},
outputDir: './generated',
files: ['./test2.ts', './test.js']
})
To document your entire project, provide an entrypoint:
await docai({
llm: {
apiKey: 'YOUR_API_KEY'
modelProvider: 'mistral' | 'openAI' | 'groq'
modelName: 'mistral-tiny' | 'gpt-4' | ...
},
outputDir: './generated',
entryPoint: './index.js'
})
To document routes from your serverless project:
await docai({
llm: {
apiKey: 'YOUR_API_KEY'
modelProvider: 'mistral' | 'openAI'| 'groq'
modelName: 'mistral-tiny' | 'gpt-4' | ...
},
outputDir: './generated',
serverlessEntryPoint: './serverless.yml'
})
baseDir
: Defaults to the current directory. Otherwise, provide the directory path.llm
:temperature
: Temperature setting for the used model (0 by default).
deleteTmpFolder
: Flag to decide whether or not to delete the temporary folder.tmpFolderPath
: Path for the temporary folder.template
: Prompt template send to the LLM to document the code, default value can be found here
Minimal Configuration: Run these commands at the root of your project:
API_KEY="YOUR_API_KEY" docai --output ./documentation --entrypoint ./src/index.js --modelProvider openAI --modelName gpt-3.5-turbo
or with Mistral
API_KEY="YOUR_API_KEY" docai --output ./documentation --entrypoint ./src/index.js --modelProvider mistral --modelName mistral-tiny
or with Groq
API_KEY="YOUR_API_KEY" docai --output ./documentation --entrypoint ./src/index.js --modelProvider groq --modelName mixtral-8x7b-32768
For a serverless project:
API_KEY="YOUR_API_KEY" docai --output ./documentation --modelProvider openAI --modelName gpt-3.5-turbo --serverless ./serverless.yml
entrypoint
: Entry point of your application. (Required)serverless
: Path to the serverless.yml file for parsing routes in serverless projects. (Required)output
: Destination folder path. (Required)modelName
: Name of the LLM model to use. (Required)modelProvider
: Name of the LLM Provider to use - openAI, mistral, groq. (Required)baseDir
: Defaults to the current directory. Otherwise, provide the directory path. (Optional)temperature
: Temperature setting for the used model (0 by default). (Optional)noDeleteTmp
: Flag to decide whether or not to delete the temporary folder. (Optional)tmpFolderPath
: Path for the temporary folder. (Optional)template
: Prompt template send to the LLM to document the code, default value can be found here. (Optional)
Only the API_KEY
environment variable is required.
You can run DocAi in local, with Ollama.
Please follow instructions from the Ollama documentation to install and run a model.
Open a terminal tab, and run a model with Ollama.
Ex: ollama run llama2
Then run DocAI with CLI or Module
docai --output ./documentation --entrypoint ./src/index.js --modelName llama2 --local --baseUrl http://localhost:11434
entrypoint
: Entry point of your application. (Required)serverless
: Path to the serverless.yml file for parsing routes in serverless projects. (Required)output
: Destination folder path. (Required)local
: Flag to local mode. (Required)modelName
: Name of the LLM model to use. (Required)baseDir
: Defaults to the current directory. Otherwise, provide the directory path. (Optional)baseUrl
: Ollama REST API endpoint, default to http://localhost:11434 (Optional)
import docai from 'docai'
await docai({
local: {
modelName: 'llama2'
baseUrl: 'http://localhost:11434' // default value, optional field
},
outputDir: './generated',
files: ['./test2.ts', './test.js']
})
Note: If you work in local mode, you can not pass llm object parameter.
You can examine the code found in _mock/test/raw/src and compare it to the documented version in _mock/test/generated/src.
- Multiple entry points.
- Multilingual capabilities.
- Frontend application documentation.
- ...
We value your feedback and contributions! If you encounter any issues or have suggestions for improvements, please feel free to submit an issue on our GitHub repository.