Blog
Supercharge your shell with OpenAI + Flox
Ross Turk | 07 May 2024
Your shell is already a powerful place.
Using a combination of small utilities and basic syntax, you can accomplish almost anything. Your shell profile is infinitely customizable, and can be molded to fit your exact workflow. The tools you use can be configured in tons of ways; you have configured yours meticulously.
You love your shell. So do we. But sometimes - just sometimes - we need answers that can't be found with grep
. We need more input.
Fortunately, Flox makes it easy to discover new tools and integrate them into the way you work. Using the Flox OpenAI environment, you can easily supercharge your shell with the ability to call upon OpenAI services. It puts the power of ChatGPT at your fingertips, giving you a few fantastic ways to use it.
Activating the environment
First, you will need an OpenAI API key. You can create one on the API Keys page.
Once you have one, you can activate the OpenAI environment on FloxHub using flox activate
and passing it the --remote
flag along with the location of the environment on FloxHub. In this case, that location is flox/openai
:
The first time you activate the environment, this might take a bit of time. After the environment is ready, it will check to see if OPENAI_API_KEY
is set. If a key can not be found, it will ask you to provide one. If you do, it will store it inside ~/.config/openai.key
for future use. You won't have to provide a key again, and subsequent activations should be instant.
If everything is set up correctly, you will see:
You will now be inside a Flox environment containing the following:
openai
: the official Python library for OpenAIchatgpt-cli
: a chat-style terminal interface for ChatGPTmods
: a delightful ChatGPT interface made for pipes and redirectsllm
: a CLI and Python library for interacting with LLMs
This is the quickest way to get your hands on this collection of tools, and far easier than following the installation instructions for just one piece, the Python library.
Using GPT to find answers
Sometimes you need a bit of help coming up with the right strategy for accomplishing a task in your shell. Search engines are okay for this, but chat is even better.
For example, I often find myself needing to work with a CSV file on the command line. Perhaps I want to see how many times each of the values in a single column occurs throughout a file. This is a simple operation, and it can be done in a few dozen ways...but I don't necessarily have the exact command sequence memorized.
For moments like these, it would be nice if we could phone a friend. The chatgpt
tool included in this environment does exactly that by allowing you to enter an interactive chat session:
This is ideal for situations where you are likely to have a follow-up question and need to maintain context. In this case, we were able to ask ChatGPT to amend its previous answer with a new requirement - to add an additional sorting of the results.
This can be really helpful. But there are times when a breadcrumb is not enough; you want ChatGPT to work directly with your data.
The mods
tool included with this environment can allow you to do exactly that: pipe data into ChatGPT alongside your text prompt. This can be used to make it do actual work, like reviewing the CSV and analyzing its contents on a deeper level.
Depending on what you're trying to learn (and how accurate it needs to be) this might help you skip all this cutting and sorting malarkey and arrive directly at your conclusion. Take a look at the examples page for mods
to learn about the other amazing things it can do.
Both of these tools are included in this Flox remote environment, and are available to use immediately after you activate it.
How does this environment work?
The manifest for flox/openai
is straightforward enough that most users can read and understand it. To prove it, I decided to write this section with ChatGPT using mods
:
By inspecting the manifest at hand, we first notice the install
section. This section lists the packages required for this project, specifying their paths. For this manifest, the packages required include openai
, llm
, gum
, chatgpt-cli
, and mods
.
Next up, we have the profile
section. Here, we can see a comprehensive setup for the OpenAI API key. The OpenAI API key enables interaction with OpenAI model interfaces. The script first tries to read the API key from the environment variable $OPENAI_API_KEY. If that's not set, it tries accessing the key stored in a file located at ~/.config/openai.key
. If it can't locate it there either, the script provides an opportunity for the user to input their OpenAI API key.
Should the user not provide the key, they shall be prompted that the OpenAI API is still accessible but without a key. It's important to note that the API key is essential to make use of OpenAI capabilities.
Lastly, we have the options
section. This specifies the compatible systems for the manifest and, by extension, this Flox environment – in this instance, systems running either 'aarch64-darwin' or 'x86_64-linux'.
This manifest provides invaluable insights into Flox's utility as an efficient project dependency installer and manager, its flexibility, and its ability to ensure a seamless development process across different systems.
And there we have it, a comprehensive guide on how to interpret this Flox environment manifest. We hope that this post was able to demystify any obstacles you may have encountered when trying to comprehend a Flox manifest file.
Give it a try!
Flox is super easy to download and use. You can use it to create environments that select from over 80,000 packages and do just about anything.
What will you use it for?