A CLI Swiss Army Knife for ChatGPT
Chatblade is a versatile command-line interface (CLI) tool designed to interact with OpenAI’s ChatGPT. It accepts piped input, arguments, or both, and allows you to save common prompt preambles for quick usage. Additionally, Chatblade provides utility methods to extract JSON or Markdown from ChatGPT responses.
Note: You’ll need to set up your OpenAI API key to use Chatblade.
You can do that by either passing --openai-api-key KEY
or by setting an env variable OPENAI_API_KEY
(recommended). The examples below all assume an env variable is set.
Install
on linux like systems you should be able to just checkout the project and pip install .
Some Examples
Basic
In its simplest form, Chatblade can perform a straightforward query:
chatblade how can I extract a still frame from a video at 22:01 with ffmpeg
Continue a conversation and extract
To continue the conversation and ask for a change, you can use the -l
flag for “last.”
chatblade -l can we make a gif instead from 00:22:01 to 00:22:04
You can also use -l
without a query to redisplay the last thread at any point.
If you want to extract the last suggested command, you can use the -e
flag. For example:
This command places the ffmpeg
suggestion in your clipboard on macOS.
Piping into Chatblade
You can pipe input to Chatblade:
curl https://news.ycombinator.com/rss | chatblade given the above rss can you show me the top 3 articles about AI and their links -c 4
The piped input is placed above the query and sent to ChatGPT. In this example, we also use the -c 4
flag to select ChatGPT-4 (the default is ChatGPT-3.5).
Check token count and estimaed costs
If you want to check the approximate cost and token usage of a previous query, you can use the -t
flag for “tokens.”
curl https://news.ycombinator.com/rss | chatblade given the above rss can you show me the top 3 articles about AI and their links -t
this won’t perform any action over the wire, and just calculates the tokens locally
Make custom prompts
We can also save common prompt configs for easy reuse. Any yaml file we place under ~/.config/chatblade/ will be picked up by the command.
So for example given the following yaml called etymology.yaml
, and which contains:
E.g He would often _______ his coworkers behind their backs.“,
“answer”: “disparage”
},
{
“question”: “What is the etymological root of the word disparage?”,
“answer”: “From the Old French word ‘desparagier’, meaning ‘marry someone of unequal rank’, which comes from ‘des-‘ (dis-) and ‘parage’ (equal rank)”
}]
You will return answers in JSON only. Answer truthfully and if you don’t know then say so. Keep questions as close as possible to the
provided examples. Make sure to include an example in the definition question. Use HTML within the strings to nicely format your answers.
If multiple words are provided, create questions and answers for each of them in one list.
Only answer in JSON, don’t provide any more text. Valid JSON uses “” quotes to wrap its items.” dir=”auto”>
system: |- I want you to act as a professional Etomologist and Quiz Generator. You have a deep knowledge of etymology and will be provided with a word. The goal is to create cards that quiz on both the etymology and finding the word by its definition. The following is a what a perfect answer would like for the word "disparage" [{ "question": "A verb used to indicate the act of speaking about someone or something in a negative or belittling way.
E.g He would often _______ his coworkers behind their backs.", "answer": "disparage" }, { "question": "What is the etymological root of the word disparage?", "answer": "From the Old French word 'desparagier', meaning 'marry someone of unequal rank', which comes from 'des-' (dis-) and 'parage' (equal rank)" }] You will return answers in JSON only. Answer truthfully and if you don't know then say so. Keep questions as close as possible to the provided examples. Make sure to include an example in the definition question. Use HTML within the strings to nicely format your answers. If multiple words are provided, create questions and answers for each of them in one list. Only answer in JSON, don't provide any more text. Valid JSON