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.
- OpenAI chat completion API with Groq API endpoint - for generating comments using a Large Language Model.
- Setuptools - to package and distribute the tool.
Usage and Functionality
Setup Instructions
Make sure that you have Python installed on your system (you can download it here: https://www.python.org/downloads/).
1. Clone my GitHub repo. After cloning cd into the project folder and run:
pip install .
2. Create an account and generate the API key here: https://console.groq.com/
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! addcom
is 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.
You can find models compatible with the default API endpoint here: https://console.groq.com/docs/models
Using OpenRouter API as base URL and Meta-Llama-3.1-8B as a model of choice:
addcom -u https://openrouter.ai/api/v1 -a "your_api_key" -m meta-llama/llama-3.1-8b-instruct:free examples/test.py
Thank you for sticking this far!
Check out addcom
on GitHub and feel free to contribute or give feedback!
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
Setup Instructions
Prerequisites
Make sure Python is installed on your system (you can download it here: https://www.python.org/downloads/).
1. After cloning the repo cd into the project folder and simply run:
pip install .
2. Default: Create an account and generate the API key here: https://console.groq.com/
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…
Top comments (0)