Chatterbox is a Swift-based command-line interface (CLI) tool that allows users to interact with OpenAI's GPT models from their terminal. This tool provides functionalities for sending messages, starting new chat sessions, specifying models, and configuring response settings. It also supports logging and archiving chat histories.
- Features
- Installation
- Configuration
- Usage
- Logging and Chat History
- Error Handling
- Troubleshooting
- Enhancing Chatterbox with .stitchrc
- License
- Interact with OpenAI GPT models via terminal.
- Send messages or start new chat sessions.
- Use various OpenAI models (e.g.,
gpt-3.5-turbo
,gpt-4
). - Adjust response temperature to control randomness.
- Customize system role message when starting a new chat.
- Archive and log chat histories with pretty-printed JSON.
- Read user input from files or directly from terminal.
You need to build the project using Swift Package Manager. Run the following command from the project directory:
swift build -c release
This will create a release build in the .build/release/
directory.
Once the project is built, you can create a symbolic link to make the executable globally available from the terminal. Run the following commands:
sudo ln -s "$(pwd)/.build/release/chatterbox" /usr/local/bin/chatterbox
This will allow you to use chatterbox
from anywhere in the terminal.
Before using Chatterbox, you need to set up a configuration file at:
~/.chatterbox/config.json
{
"apiKey": "your-openai-api-key",
"defaultModel": "gpt-4",
"temperature": 0.7,
"topP": 0.9,
"maxTokens": 150,
"logDirectory": "/home/username/.chatterbox/logs"
}
apiKey
: Your OpenAI API key.defaultModel
: The default GPT model to use (e.g.,gpt-3.5-turbo
,gpt-4
).temperature
: Controls response randomness. Values between 0.0 (deterministic) and 1.0 (creative).topP
: Controls the nucleus sampling parameter for response generation.maxTokens
: The maximum number of tokens in the response.logDirectory
: Path to store chat logs. Ensure this directory exists.
-
Navigate to the Configuration Directory:
mkdir -p ~/.chatterbox cd ~/.chatterbox
-
Create the
config.json
File:touch config.json
-
Edit the File: Open
config.json
in your favorite text editor and add your API key, model, and other settings as shown in the example. -
Ensure the API Key is Set: Make sure you have a valid OpenAI API key in the
apiKey
field.
Once Chatterbox is installed and the configuration is set up, you can interact with it using various commands from the terminal.
To send a message to the assistant:
chatterbox "Hello, how are you?"
To start a new chat session:
chatterbox --new "Tell me a joke."
To specify which GPT model to use:
chatterbox --model gpt-4 "Explain quantum mechanics."
To control how random or creative the assistant's responses are, set the temperature:
chatterbox --temperature 0.5 "What is the capital of France?"
To set a custom system message when starting a new chat session:
chatterbox --new --system-message "You are a financial advisor." "What are the best investment strategies?"
To enable verbose logging for detailed output:
chatterbox --verbose "Summarize the book '1984'."
To read the input message from a file:
chatterbox --file path/to/input.txt
Chatterbox automatically saves chat histories in the directory specified in your configuration (logDirectory
).
By default, logs are stored in:
~/.chatterbox/logs/
- Chat logs are saved as pretty-printed JSON files with timestamps.
- When a new chat session is started, the old session is archived.
If the configuration file (~/.chatterbox/config.json
) is missing, Chatterbox will return an error message similar to the following:
Configuration file is missing at /home/username/.chatterbox/config.json. Please refer to the README.md for instructions on how to create the config.json file.
This ensures that you know where the issue lies and can fix it by setting up the necessary configuration.
- Command Not Found: Ensure you created the symlink to
/usr/local/bin/chatterbox
and that/usr/local/bin
is in your system’sPATH
. - Invalid API Key: Verify your API key is correct in the
config.json
file. - Logging Issues: Ensure the
logDirectory
specified in the configuration exists and that Chatterbox has permission to write to it.
The .stitchrc
file provides a Zsh function named stitch
that can be used to combine multiple code files from a specified directory into a single, formatted output. This can be useful for preparing code snippets or documentation.
-
Add the
stitch
Function to Your.zshrc
: Copy the content of.stitchrc
into your.zshrc
file to make thestitch
function available in your terminal sessions. -
Create a Soft Link to Home: If you have a separate
.stitchrc
file, you can create a symbolic link to it in your home directory:ln -s /path/to/.stitchrc ~/.stitchrc
-
Source the
.stitchrc
in Your.zshrc
: Add the following line to your.zshrc
to source the.stitchrc
file:source ~/.stitchrc
-
Reload Your Zsh Configuration: After updating your
.zshrc
, reload it with:source ~/.zshrc
-
Combine Files: Use
stitch
to combine files in a directory:stitch src
-
Recursive Combination: Combine files recursively:
stitch -r src
-
Output to Clipboard: Combine files and copy to clipboard:
stitch -o clipboard src
This function respects .gitignore
files and can skip binary files, making it a powerful tool for managing code snippets and documentation.
This project is licensed under the MIT License. See the LICENSE file for more details.