Chatblade: The CLI Swiss Army Knife for ChatGPT - Interact, Generate, and Extract with Ease!

If you are looking for a powerful and easy-to-use tool to interact with OpenAI's ChatGPT, you might want to check out Chatblade. Chatblade is a command-line interface (CLI) tool that lets you chat with ChatGPT, generate text, and extract useful information from the responses. In this blog post, we will see some of the features of Chatblade and what benefits we can get out of it. Before we start, let's just quickly understand ChatGPT.

Chatblade - A CLI Swiss Army Knife for ChatGPT


What is ChatGPT?

ChatGPT is a natural language processing (NLP) model developed by OpenAI that can generate coherent and engaging text based on a given prompt. You can use ChatGPT to create content such as blog posts, stories, lyrics, code, and more. You can also chat with ChatGPT and ask it questions or have a conversation.


What is Chatblade?

Chatblade is a CLI tool that makes it easy to interact with ChatGPT. You can use Chatblade to:

  • Start a new conversation or continue an existing one with ChatGPT
  • Switch between different versions of ChatGPT (3.5 or 4)
  • Stream the responses from ChatGPT in real time
  • Format the responses as markdown or extract code blocks or JSON data
  • Save common prompts for quick usage
  • Pipe input or output to other commands

Chatblade Example video

How to install Chatblade?

To use Chatblade, you need to have an OpenAI API key. You can get one by signing up for OpenAI's beta program. Once you have your key, you can set it as an environment variable called OPENAI_API_KEY or pass it as an argument to Chatblade.

There are several ways to install Chatblade:

  • To get the latest version from GitHub, you can run `pip install 'chatblade @ git+https://github.com/npiv/chatblade'`
  • To get the last released version from PyPI, you can run `pip install chatblade --upgrade`
  • To install via Homebrew, you can run `brew install chatblade`


How to use Chatblade?


To use Chatblade, you just need to type `chatblade` followed by your query. For example, if you want to chat with ChatGPT about movies, you can type:

chatblade What is your favorite movie genre?

Chatblade will then send your query to ChatGPT and display the response in your terminal. You can also use the `-i` flag to enter an interactive mode where you can chat with ChatGPT continuously.

If you want to switch between different versions of ChatGPT, you can use the `-c` flag followed by the version number (3.5 or 4). For example, if you want to use ChatGPT-4, you can type:

chatblade -c 4 How do you feel about climate change?

If you want to stream the responses from ChatGPT in real time, you can use the `-s` flag. This will show you how ChatGPT generates the text word by word. You can also combine this with the interactive mode by using `-s -i`.

If you want to format the responses as markdown or extract code blocks or JSON data, you can use the `-r` or `-e` flags respectively. For example, if you want to generate a python script that prints hello world and save it as main.py, you can type:

chatblade -e write me a python boilerplate script that starts a server and prints hello world > main.py
You can also load custom prompts which are system messages to instruct the model about how its behavior is going to be. The option '-p' can be used for this. By default it picks the files placed in the location - ~/.config/chatblade/, but you can also point it to any file path. 

The system message includes additional instructions on how to behave or act during the conversation. It also provides a couple of example questions and answers to give users an idea of how they can interact with the AI model. 

Chatblade - System Messages Example


If we can create a file called introduction to store the prompts, we can use this system message file by running the command:

chatblade -p introduction


If you want to pipe input or output to other commands, you can use standard shell syntax. For example, if you want to generate a haiku about cats and send it as an email, you can type:

echo Generate a haiku about cats | chatblade -r | mail -s "Haiku" someone@example.com


This was just a glimpse of what is possible with Chatblade but there is more to it. You can check this awesome CLI tool here at - https://github.com/npiv/chatblade

Chatblade - Piped Input


Chatblade is a versatile and powerful tool that lets you interact with OpenAI's ChatGPT in various ways. You can use Chatblade to chat, generate text, and extract information from the responses. You can also customize your queries, format your output, and integrate with other commands. Chatblade is a CLI Swiss Army Knife for ChatGPT that you should definitely try out.


Also Read:


No comments: