Simple pair programming/chat assistant CLI and Web App powered by OpenAI (defaults to "gpt-4" model).
- Requirements
- Features
- Installation
- Configuration
- Usage (CLI)
- Usage (Web App)
- Training the Tokenizer
- Thanks and Enjoy
- Python (12.2.0+ recommended)
- OpenAI API key (free or paid)
- Chat with
gpt-4in your terminal or browser - Set the system prompt during the conversation
- Upload and inject file context (webapp only)
- Live Markdown preview as you type (webapp)
- Syntax highlighting and copy-to-clipboard for code blocks
- Download chat history as Markdown
- Start new chat sessions with confirmation and save prompts
- Train the BPE tokenizer with your own chat logs
- Markdown formatted chat responses
git clone https://github.com/Michelleeby/pAIr.git && cd pAIr
echo "12.2.0" > .python-version
if [ -d "pair" ]; then
source pair/bin/activate
else
python -m venv pair
source pair/bin/activate
fi
pip install -r requirements.txtThe webapp uses only static HTML/CSS/JS, so no build step or npm install is needed for basic use.
If you want to customize themes or bundle, see the /static folder.
pAIr uses environment variables (from .env) for configuration.
Minimum required:
OPENAI_API_KEY=your-api-key-hereAll supported variables:
OPENAI_API_KEY=your-api-key-here
GPT_MODEL_NAME=gpt-4
MODEL_PATH=pair.pkl
TRAINING_DATA_PATH=sample-training-data.log
PAT_STR=('s|'t|'re|'ve|'m|'ll|'d| ?[\p{L}]+| ?[\p{N}]+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+)|(```[\s\S]*?```)|(`[^`]*`)|(\[[^\]]*\]\([^)]*\))After setup, activate your environment:
source pair/bin/activateStart the chat assistant:
python pair.pyOr add an alias in your .bashrc or .zshrc:
echo "alias pair='source $(pwd)/pair/bin/activate && python $(pwd)/pair.py && deactivate'" >> ~/.bashrc
source ~/.bashrc- Start chatting in the terminal with Markdown support
- Multiline message entry (press
Ctrl+Dto send) - Type
quitand pressCtrl+Dto exit - Responses formatted in Markdown for easy reading
- System prompt can be set/updated interactively (
set_system) - Chat history saved in
chat.log
Type set_system and press Ctrl+D. You'll be prompted to append to/reset the default system message.
The system prompt makes the assistant always return fully Markdown formatted responses, with clear sections for code and explanations.
You can use the web app to access all the features of the CLI and more, via a modern browser interface.
After setup, activate your environment and start the FastAPI backend:
uvicorn app:app --reloadThen open your browser and visit: http://localhost:8000
- Chat History: Shows all messages in Markdown, with highlighted code
- Live Preview: Type your message in Markdown and see a live, rendered preview before sending
- File Context: Drag & drop or select multiple files to provide them as context to the assistant (files sent along with your message)
- Download Chat: Save the current chat history as a
.mdMarkdown file with a click - Start New Chat: Clears the chat and starts a new session, with save prompt if history not yet downloaded
- Copy Buttons: Easily copy any AI code block or full response with one click
- Dark/Light Theme: Automatically adapts to your OS preference
- Type your message (supports Markdown, including code blocks)
- Optionally, select/drag files to inject as context (assistant will prioritize your files for this reply)
- Click Send or press
Enter - Read the AI's response with formatting and code highlights
- Drop any number of
.txt,.py,.md, or similar files in the dropzone - Remove files from the queue before sending if needed
- Files are sent with your next message
- Download your conversation anytime as a clean, formatted Markdown file
- All user and assistant messages are saved (excluding system messages by default)
- The webapp applies the same system prompt as the CLI for each session
- Future updates may allow specifying/changing it interactively
- Switches between light/dark automatically, respecting your device/system preferences
You can train your own tokenizer for more efficient message encoding and cost savings.
The code will default to training from the sample-training-data.log file provided. To use your own data, set the TRAINING_DATA_PATH variable in .env.
If the tokenizer model file (MODEL_PATH) doesn't exist, the system will train and save a new one on first run.
Sample pattern (PAT_STR) is suitable for chat logs and Markdown code:
pat_str = r"""('s|'t|'re|'ve|'m|'ll|'d| ?[\p{L}]+| ?[\p{N}]+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+)|(```[\s\S]*?```)|(`[^`]*`)|(\[[^\]]*\]\([^)]*\))"""pAIr is Open Source. Contributions, bug reports, and suggestions welcome!
For more, see:
Need help? Open an Issue on GitHub or start chatting right away with pAIr! 🚀