gencmd - Generate commands with Generative AI
Command line arguments are notoriously difficult to remember. To find the right options requires breaking your flow — change from your terminal to a browser, open a tab, enter your query, scan through a few likely links, open each, read through the pages, and then copy-paste one of the options into your terminal. gencmd can simplify that dramatically by giving you relevant options in the terminal itself.
gencmd integrates Generative AI into the cmd line to suggest relevant cmd line options.
Register, get the cli version, and run it from the terminal: https://gencmd.com/register-user
Or quickly try it out in the browser at: https://gencmd.com/search
gencmd Examples
gencmd -n 5 -t 0.9 convert the first 10 seconds of an mp4 video into a gif
# -n is the (max) number of results
# -t is the temperature.
ffmpeg -ss 00:00:10 -i input.mp4 -vcodec gif -pix_fmt rgb24 -t 00:00:10 output.gif
ffmpeg -ss 00:00:00 -i input.mp4 -t 00:00:10 -vf "scale=320:-1,fps=25,format=gif" output.gif
ffmpeg -ss 00:00:10 -i input.mp4 -vf "fps=10,scale=320:-1" output.gif
ffmpeg -ss 00:00:10 -i input.mp4 -vf scale=320:-1 -pix_fmt yuv420p output.gif
ffmpeg -i input.mp4 -vf "trim=0:10" output.gif
gencmd -i -c grep find txt files that contain the text hello
gencmd -o windows -n 1 find files that has extension pdf
gencmd -c git -n 2 recursively remove a directory from git but not from local
gencmd -c gcloud delete a vm named instance-1 in iowa region zone a
gencmd -c kubectl delete a pod named hello in namespace n2
MakerSuite sprint
As part of a MakerSuite Sprint in September, I was given access to the PaLM API. I had a few ideas, out of which I completed two. I’ll elaborate on gencmd in this article.
Since I use the command line extensively, I want to get cmd line arguments as quickly as possible. I frequently use git, ffmpeg, grep, sed, gcloud, kubectl, find, ng, firebase, etc., but for the life of me, I can’t remember all the commands. And honestly, I don’t want to. To paraphrase Sherlock Holmes/Arthur Conan Doyle, your mind is a limited capacity room and you don’t want the trivial things crowding out the significant. So, let’s leave all those pesky, long, convoluted command line options to gencmd, what say?
Generative AI with MakerSuite, PaLM AI API
Step 1: MakerSuite
MakerSuite lets you experiment with prompts in its web UI — Text, Data, and Chat. For this project I wasn’t providing any data samples for which Data prompt would have been the starting point, and neither did I need a conversational approach for which Chat prompt would have been the right option. Text prompt was the right approach for the gencmd use case.
So, I tried out a few prompts, and lo and behold, I got some pretty good results. Sometimes, it had additional artifacts and there were some repetitions but it was very useful right away. Instead of having to search multiple docs and web pages, I could have a set of good options in a single place. Great start! And it took only a few minutes to validate that.
Step 2: Integrating into the cmd line
PaLM APIs can be called using cURL, REST, or libraries in languages like Python and Node. There is a “Get Code” link on the top-right that gives you starting code. The image below is for JavaScript.
I initially decided to use shell script. So I copied the cURL command, added the API_KEY as an environment variable, and sent in my cmd line query as the rest of the parameters. Easy peasy.
curl \
-H ‘Content-Type: application/json’ \
-X POST ‘https://generativelanguage.googleapis.com/v1beta2/models/text-bison-001:generateText?key='${API_KEY} \
-d ‘{ “prompt”: { “text”: “”}, “temperature”: 0.7, “top_k”: 40, “top_p”: 0.95, “candidate_count”: 1, …
I enhanced the shell script to provide options, cleant up responses from PaLM, etc. That code is open sourced. You can see the code here: https://github.com/sathishvj/gencmd-bash
Enlightenment
The productivity boost I got from the initial shell script was excellent. Not only was this utility cool, but it helped me retain a congruent cmd line workflow by not having to shift to browsers, web pages, copying, and then returning to paste.
Step 3: Rewriting in Go
Having seen my personal productivity improve, I decided to share it with others. But bash isn’t that universal. I wanted the tool to be cross platform, easy to distribute, and maintain. So I rewrote the cli in Go. That original source code is here: https://github.com/sathishvj/gencmd-go
Step 4: Not Universal Enough with PaLM API Key Requirement
The cli still required an API key for PaLM API, and that wasn’t easy to get for everybody. It also required having a Google Cloud account and managing the keys therein. So, not very universal or easily distributable.
Hence, I decided to write a commercial version. I hold the PaLM API key in a Google Cloud Secret Manager and I provide you a unique API key that you can manage. This was a larger undertaking involving a full stack of technologies. I mainly used Firebase/Firestore, Angular 16 + TypeScript, Bootstrap and Bootstrap Icons, and Firebase Functions with JavaScript to build a web property that allows you to use an updated gencmd cli tool written in GoLang. I also have BigQuery + Looker Studio for analysis.
gencmd.com
https://gencmd.com has a Search page that calls Generative AI in the backend. If you want to quickly try out gencmd input/output, the web interface is good.
To get the full power of gencmd and the seamless workflow in the terminal, I recommend you install the cli. The instructions to download and configure the cli are available once you create an account and sign-in. (see image below)
Timelines and Technologies
One of the things that surprised me, honestly, is how quickly I was able to make a functional MVP (or three) within such short timelines that integrates powerful technologies.
gencmd-bash: ~8th Sept to about 10/11th September
gencmd-go: about 10/11th September to 13th September
explainmodelnumber.com: 14th September to 17th September (another small app I did for #MakerSuiteSprint)
gencmd.com website + cli: about 18th September to 25th September, with maybe a day off in between.
original draft of this post: ~26th September
Since I’ve been doing quite different work in the past few years, I was rusty on Angular, Observables and Promises, Bootstrap, and even Go to an extent. I had to spend at least a day reviewing and relearning Observables and Promises. I have never done Firebase functions or built an end to end product with Firebase. I hadn’t done pure JavaScript or TypeScript for ages and I was surprised by some new syntax. I had, however, integrated Github Copilot, Idea’s AI Assistant, and Google’s Duet AI into my IDE which gave great guidance and good boost to my programming productivity. Truly amazing technologies and I hope to continue utilizing all these to build more useful apps.
More Features Soon for gencmd
I’ve got a list of features in the pipeline. For example, using custom LLMs, ability to route searches to one of many chosen LLMs, auditable history (for Enterprises which need that for compliance), fast cache, etc.
For now, I’m eager to know your feedback and how it improved your workflow and productivity.
github copilot cli: When I wrote this app and also when I wrote the original draft of this post, I had no idea about a similar tool from github. Since I learned about it very recently I tried to use it, but apparently it needs different approvals from the IDE integrated Copilot. So, I’m on the waitlist for now. Looking at some articles and videos though, the end goal is similar to gencmd. So you can try that out too, if you have access.
Source Code
First written in bash script: https://github.com/sathishvj/gencmd-bash
Then re-written in GoLang: https://github.com/sathishvj/gencmd-go
And finally, now available in a commercialized form: https://gencmd.com
Contact
I am on LinkedIn mostly. For my Google Cloud videos, you can check out AwesomeGCP.