Hello blog! I am excited to introduce my latest project, a CLI tool called addcom.
What is addcom?
addcom is a command-line tool created to help coders annotate their source code. To use it, you need to provide a relative or absolute path to your file, and addcom will analyze the code and generate comments using a Large Language Model's chat completion.
See a demo of the functionality on YouTube: addcom-demo
How I built it
I made addcom as part of my Open Source course assignment, where we were tasked to create a CLI tool that developers to leverage any OpenAI-compatible Chat Completion API endpoint to transform files in a helpful way.
I had never created a command-line interface tool before, so naturally, figuring out the right approach took some exploration.
From the start, I knew that I wanted to write addcom in Python. After watching a few different "build a CLI tool with Python" YouTube tutorials, taking a peek into my classmates' repositories and reading through the Release 0.1 wiki page, I finally settled on the right toolset:
Typer - a framework created for making CLI applications.
By default, addcom uses the Groq API endpoint for chat completion. However, you can specify a custom endpoint using the --base-url or -u flag option. (If you do this, make sure to obtain an appropriate API key and specify the model supported by the chosen provider using the --model/ -m option).
3. Set the API key
To do this you can expose the API key to the terminal environment:
Command Prompt
set GROQ_API_KEY=your_api_key_here
Powershell
$env:ADDCOM_API_KEY="your_api_key_here"
Bash
$env:ADDCOM_API_KEY="your_api_key_here"
or provide the key using the --api-key/ a option flag.
4. Congrats! addcomis ready to use. To add comments to your source code files, simply run the command along with the file paths.
addcom [OPTIONS] FILE_PATH(S)...
Features
Apart from its core functionality (utilizing Groq API and Llama3 to generate comments and printing the annotated code to standard output) addcom supports a number of additional features:
Displaying a comprehensive help message with the --help flag
addcom --help
Showing the current tool version using --version / -v
addcom --version
Saving the commented code to the specified file using --output/ -o
If multiple files are specified, the commented source code from all files will be combined and saved into a single output file.
addcom examples/test.py -o commented_test.py
Providing the API key directly via cli option --api-key/ -a.
Passing the API key using this option will override the API key that was exposed to the terminal.
addcom --api-key "your_api_key" examples/test.py
Specifying an API endpoint (--base-url/ -u) and Large Language Model (--model/ -m) to be used for generating the comments
If you decide to use a custom API endpoint, make sure to obtain an appropriate API key and specify a Large Language Model supported by the API of your choice.
a CLI tool for adding comments to your source code files
ADDCOM
addcom is a CLI source code documenter tool which provides coders with an easy way to add comments to their source code files
Give it a relative/absolute path to your file and it will analyze its contents and add comments using a Large Language Model's chat completion.
See a demo of the functionality on YouTube: addcom-demo
By default, addcom uses the Groq API endpoint for chat completion. However, you can specify a custom endpoint using the --base-url or -u flag option. (If you do this, make sure to obtain an appropriate API key and specify the model supported by the chosen provider using…