A CLI Swiss Army Knife for ChatGPT
Chatblade is now archived and no longer under active development. It did its job in the early days of LLM tooling, but today you’re generally better off using Claude Code or Codex directly.
If you’re looking for a modern CLI in the same spirit, I recommend llm (https://github.com/simonw/llm) or Fabric (https://github.com/danielmiessler/Fabric).
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.
To stay up to date with the current main branch you can:
pip install .pip install 'chatblade @ git+https://github.com/npiv/chatblade'The last released version can be installed with pip install chatblade --upgrade
brew install chatbladeYou can begin any query by just typing. f.e.:
chatblade how can I extract a still frame from a video at 22:01 with ffmpegif you would like to recall the last conversation just call it back with -l
chatblade -lTo continue the conversation and ask for a change within the context, you can again use -l but with a query.
chatblade -l can we make a gif instead from 00:22:01 to 00:22:04-l is shorthand for -S last or the last session. We can keep track of and continue various distinct conversations using the session options
By default, gpt-3.5 is used, you can switch at any point to 4 by using -c 4 or the latest 4o ("omni") by using -c 4o.
Additionally, you can pass any arbitrary full model name, f.e. -c gpt-3.5-turbo-16k.
If you preferred to chat interactively instead just use chatblade -i.
You can also stream the responses, just like in the webui. At the end of the stream it will format the result. This can be combined in an interactive session
chatblade -s -i
https://user-images.githubusercontent.com/452020/226891636-54d12df2-528f-4365-a4f3-e51cb025773c.mov
Responses are parsed and if chatblade thinks its markdown it will be presented as such, to get syntax highlighting. But sometimes this may not be what you want, as it removes new lines, or because you are only interested in extracting a part of the result to pipe to another command.
In that case you have 2 options:
-r for raw, which just prints the text exactly as ChatGPT returned it, and doesn't pass it through Markdown.-e for extract, which will try to detect what was returned (either a code block or json) and extract only that part. If neither of those are found it does the same as -rBoth options can be used either with a new query, e.g.
chatblade -e write me a python boilerplate script that starts a server and prints hello world > main.pyor with the last result (json in this example)
chatblade -l -e | jqIf we have long prompts we don't want to type everytime, or just want to provide context for our query we can pipe into chatblade.
e.g.
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 4The piped input is placed above the query and sent to ChatGPT.
or
chatblade what does this script do < script.shWhat gets sent to ChatGPT over the wire is:
piped input
-------
querySessions are named conversations.
If you start chatblade with a session name SESS of your choice:
chatblade -S SESS can we make a gif instead from 00:22:01 to 00:22:04chatblade will create a session called SESS if it does not exist, and it will store the current exchange (query-response pair) for SESS.
If such a session already exists, the saved conversation will be loaded and the new exchange will be appended.
Without a session argument, the exchange also gets stored in a session named last; however, subsequent sessionless invocation will overwrite the content of last. (You can continue a conversation that was started as a sessionless exchange by passing -S last, but last won't be a safe space for keeping a conversation, as the next sessionless invocation will clear it again.) The -l option is provided as a shorthand for -S last.
If you specify a session without a query:
chatblade -S SESSchatblade will recall the conversation without modifying the session.
chatblade supports various operations on sessions. It provides the --session-OP options, where OP can be list, path, dump, delete, rename.
If you want to check the approximate cost and token usage of a previous query, you can use the -t flag for "tokens."
We could do this when passing in a lot of context like in the example above for instance.
curl https://news.ycombinator.com/rss | chatblade given the above rss can you show me the top 3 articles about AI and their links -tThis won't perform any action over the wire, and just calculates the tokens locally.
The system message is used to instruct the model how to behave, see OpenAI - Instructing Chat Models.
These can be loaded with -p. For convenience any file we place under ~/.config/chatblade/ will be picked up by this command.
So for example, given the following file ~/.config/chatblade/etymology, which contains:
…We can now run a command and refer to this prompt with -p etymology:
chatblade -p etymology gregariousYou can also point -p to a file path directly to load a system message from any arbitrary location
And since we asked for JSON, we can pipe our result to something else, e.g.:
chatblade -l -e > toankichatblade can be used with an Azure OpenAI endpoint, in which case in addition to the OPENAI_API_KEY you'll need to set the following environment variables:
OPENAI_API_TYPE :: Set to azure. As required by openai-pythonAZURE_OPENAI_ENDPOINT :: URL to your cognitive services' endpoint, e.g. https://eastus.api.cognitive.microsoft.com/. Please note this is a breaking change introduced by openai-python and the previous environment variable name is OPENAI_API_BASEOPENAI_API_AZURE_ENGINE :: name of your deployment in Azure, f.e. my-gpt-35-turbo (maps to a specific model)Note: that this will override any option for -c 3.5 or -c 4 which don't make sense in this case.
…No open issues yet, or sync has not completed.