Awesome
Cha
Overview
Cha is an open-source command-line tool that simplifies interactions with AI models from OpenAI. It allows users to efficiently engage with powerful language models directly from their terminal, enhancing development workflows. Check out the detailed demo here.
Features
- CLI Chat Interface: Communicate with OpenAI's models via commands
cha
- Interactive & Non-interactive Modes: Interact with models via chat interface, command-line arguments, or file input.
- Multi-line Input Mode: Simplifies complex input directly into the CLI.
- Text-Editor Input Mode: Use your system's terminal based text editor instead of Python's
input()
, allowing easier input of complex and long prompts. - Web and YouTube Scraping: Extract YouTube video transcripts, web pdfs, and general web content.
- Image Generation: Generate custom images using OpenAI's image models.
- Answer Search: Simple implementation of an Answer-Search engine similar to Perplexity AI's solution
- Estimate Tokens: Option to estimate the token count for a file, string, or piped content.
Vision
Cha is a simple, lightweight CLI tool that provides access to powerful AI models directly from the terminal. Think of it like Vim versus Emacs: Cha focuses on simplicity and versatility, delivering essential functionality without overwhelming complexity. It's designed to fit seamlessly into your workflow, helping to reduce the need for developers to leave their terminals, making AI access and general knowledge querying straightforward and efficient.
Getting Started
Installation
-
Clone the Repository:
git clone <repository-url> cd <repository-folder>
-
Install the Package:
pip3 install --upgrade .
Configuration
-
API Keys Setup: Grab your API keys from the following links
- OpenAI API key
- (optional) Brave Search API key
-
Setup your .env file: Create a
.env
file in the root directory and add your keysexport OPENAI_API_KEY="YOUR_OPENAI_API_KEY" # (optional) this key is only needed if you want to use the Answer-Search feature export BRAVE_API_KEY="YOUR_BRAVE_SEARCH_API_KEY"
-
Apply the environment variables
source .env
-
Configure Micro IDE for Editor Input Mode (Optional):
Cha's Text-Editor Input Mode can use terminal-based text editors like vim, vi, nano, or emacs. For a simple and streamlined experience, we recommend Micro with the specific configuration below.
- Install the Micro IDE: Micro IDE Installation Guide
- Edit the configuration file:
~/.config/micro/bindings.json
- Add the following key-value:
{ "Ctrl-q": "Save,Quit" }
By making this change, you can just start writing immediately then easily save and exit the Micro editor using
Ctrl-Q
when working in Cha's Text-Editor Input Mode.
Usage
To start using cha, run the following simple command:
cha
Both commands support and accept additional parameters. Here are all of their respected help page for reference:
usage: cha [-h] [-pt] [-as] [-m MODEL] [-sm] [-f FILE] [-i [IMAGE]] [-t]
[string ...]
Chat with an OpenAI GPT model.
positional arguments:
string Non-interactive mode, feed a string into the
model
options:
-h, --help show this help message and exit
-pt, --print_title Print initial title during interactive mode
-as, --answer_search Run answer search
-m MODEL, --model MODEL
Model to use for chatting
-sm, --select_model Select one model from OpenAI's supported models
-f FILE, --file FILE Filepath to file that will be sent to the model
(text only)
-i [IMAGE], --image [IMAGE]
Generate image (flag only) or print the metadata
for generated images (provide filepath)
-t, --token_count Count tokens for the input file or string
Docker
Cha can be run in Docker and accessed through the browser. This is great if you want to access Cha from the browser and/or avoid installing the dependencies for Cha by running it in a sandbox. To setup and run the Docker version of Cha, checkout this section of the repo.
Development
For those interested in contributing or experimenting with Cha:
-
Install in Editable Mode:
pip install -e .
-
Develop and Test: Modify the source code and test changes using
cha
. -
(optional) Load your Custom Configuration: Use the
CHA_PYTHON_CUSTOM_CONFIG_PATH
environment variable to point to a customconfig.py
file that overrides default global variables. Set it usingexport CHA_PYTHON_CUSTOM_CONFIG_PATH="/path/to/your/config.py"
. Make sure your defined variables is all uppercase.
Contributing
Any contribution is always welcomed! Please feel free to submit issues or pull requests for any bugs or features.
License
Cha is licensed under the MIT License. See LICENSE for more details.
Acknowledgments
Cha is inspired and/or made possible thanks to: