๐๏ธ Perspt: Your Terminal's Window to the AI World ๐ค
"The keyboard hums, the screen aglow,
AI's wisdom, a steady flow.
Will robots take over, it's quite the fright,
Or just provide insights, day and night?
We ponder and chat, with code as our guide,
Is AI our helper or our human pride?"
Perspt (pronounced "perspect," short for Personal Spectrum Pertaining Thoughts) is a high-performance command-line interface (CLI) application that gives you a peek into the mind of Large Language Models (LLMs). Built with Rust for speed and reliability, it allows you to chat with various AI models from multiple providers directly in your terminal using the modern genai crate's unified API.
๐ฏ Why Perspt?
- ๐ Latest Model Support: Built on the modern
genaicrate with support for latest reasoning models like Google's Gemini 2.5 Pro and OpenAI's o1-mini - โก Real-time Streaming: Ultra-responsive streaming responses with proper reasoning chunk handling
- ๐ก๏ธ Rock-solid Reliability: Comprehensive panic recovery and error handling that keeps your terminal safe
- ๐จ Beautiful Interface: Modern terminal UI with markdown rendering and smooth animations
- ๐ค Zero-Config Startup: Automatic provider detection from environment variables - just set your API key and go!
- ๐ง Flexible Configuration: CLI arguments, environment variables, and JSON config files all work seamlessly
โจ Features
- ๐จ Interactive Chat Interface: A colorful and responsive chat interface powered by Ratatui with smooth scrolling and custom markdown rendering.
- โก Advanced Streaming: Real-time streaming of LLM responses with support for reasoning chunks and proper event handling.
- ๐ค Automatic Provider Detection: Zero-config startup that automatically detects and uses available providers based on environment variables (set
OPENAI_API_KEY,ANTHROPIC_API_KEY, etc. and just runperspt!). - ๐ Latest Provider Support: Built on the modern
genaicrate with support for cutting-edge models:- OpenAI (GPT-4, GPT-4-turbo, GPT-3.5-turbo, GPT-4o, GPT-4o-mini, GPT-4.1, o1-mini, o1-preview, o3-mini, and more)
- Anthropic (Claude-3 Opus, Sonnet, Haiku, Claude-3.5 Sonnet, Claude-3.5 Haiku, and more)
- Google Gemini (Gemini-1.5-pro, Gemini-1.5-flash, Gemini-2.0-flash, Gemini-2.5-Pro, and more)
- Groq (Llama models with ultra-fast inference, Mixtral, Gemma, and more)
- Cohere (Command models, Command-R, Command-R+, and more)
- XAI (Grok models and more)
- DeepSeek (DeepSeek-chat, DeepSeek-reasoner, and more)
- Ollama (Local models: Llama, Mistral, Code Llama, Vicuna, and custom models)
- ๐ง Robust CLI Options: Full command-line support for API keys, models, and provider types that actually work.
- ๐ Flexible Authentication: API keys work via CLI arguments, environment variables, or configuration files.
- โ๏ธ Smart Configuration: Intelligent configuration loading with fallbacks and validation.
- ๐ Input Queuing: Type and submit new questions even while the AI is generating a previous response.
- ๐ Enhanced UI Feedback: Visual indicators for processing states and improved responsiveness.
- ๐ Custom Markdown Parser: Built-in markdown parser optimized for terminal rendering with proper streaming buffer management.
- ๐ก๏ธ Bulletproof Error Handling: Comprehensive panic recovery, network resilience, and user-friendly error messages.
- ๐ Extensive Documentation: Comprehensive code documentation and user guides.
๐ Getting Started
๐ค Zero-Config Automatic Provider Detection
NEW! Perspt now features intelligent automatic provider detection. Simply set an environment variable for any supported provider, and Perspt will automatically detect and use it - no additional configuration needed!
Priority Detection Order:
- OpenAI (
OPENAI_API_KEY) - Anthropic (
ANTHROPIC_API_KEY) - Google Gemini (
GEMINI_API_KEY) - Groq (
GROQ_API_KEY) - Cohere (
COHERE_API_KEY) - XAI (
XAI_API_KEY) - DeepSeek (
DEEPSEEK_API_KEY) - Ollama (no API key needed - auto-detected if running)
Quick Start Examples:
# Option 1: OpenAI (will be auto-detected and used)
# Option 2: Anthropic (will be auto-detected and used)
# Option 3: Google Gemini (will be auto-detected and used)
# Option 4: Ollama (no API key needed!)
# Just make sure Ollama is running: ollama serve
What happens behind the scenes:
- Perspt scans your environment variables for supported provider API keys
- Automatically selects the first available provider (based on priority order)
- Sets appropriate default model for the detected provider
- Starts up immediately - no config files or CLI arguments needed!
When no providers are detected: If no API keys are found, Perspt shows helpful setup instructions:
# ... (shows all supported providers)
Read the perspt book - This illustrated guide walks through the project and explains key Rust concepts
๐ ๏ธ Prerequisites
- Rust: Ensure you have the Rust toolchain installed. Get it from rustup.rs.
- ๐ LLM API Key: For cloud providers, you'll need an API key from the respective provider:
- OpenAI: Get yours at platform.openai.com (supports o1-mini, o1-preview, o3-mini, GPT-4.1)
- Anthropic: Get yours at console.anthropic.com
- Google Gemini: Get yours at aistudio.google.com (supports Gemini 2.5 Pro)
- Groq: Get yours at console.groq.com
- Cohere: Get yours at dashboard.cohere.com
- XAI: Get yours at console.x.ai
- DeepSeek: Get yours at platform.deepseek.com
- Ollama: For local models, install Ollama from ollama.ai (no API key needed)
๐ฆ Installation
-
Clone the Repository:
-
Build the Project:
Find the executable in the
target/releasedirectory. -
Quick Test (Optional):
# Test with OpenAI (replace with your API key) # Test with Google Gemini (supports latest models) # Test with Anthropic
โ๏ธ Configuration
Perspt can be configured using a config.json file or command-line arguments. Command-line arguments override config file settings.
๐ Config File (config.json)
Create a config.json in the root directory of the project, or specify a custom path using the -c CLI argument.
Example config.json:
Configuration Fields:
providers(Optional): A map of provider profile names to their API base URLs.provider_type: The type of LLM provider to use.- Valid values:
"openai","anthropic","gemini","groq","cohere","xai","deepseek","ollama"
- Valid values:
default_provider(Optional): The name of the provider profile from theprovidersmap to use by default.default_model: The model name to use (e.g., "gpt-4o-mini", "claude-3-5-sonnet-20241022", "gemini-1.5-flash").api_key: Your API key for the configured provider.
Example configurations for different providers:
OpenAI:
Anthropic:
Google Gemini:
Groq:
Cohere:
XAI (Grok):
DeepSeek:
Ollama (Local Models):
โจ๏ธ Command-Line Arguments
The CLI now has fully working argument support with proper API key handling:
-c <FILE>,--config <FILE>: Path to a custom configuration file.-p <TYPE>,--provider-type <TYPE>: Specify the provider type (openai,anthropic,gemini,groq,cohere,xai,deepseek,ollama).-k <API_KEY>,--api-key <API_KEY>: Your API key for the LLM provider (works properly now!).-m <MODEL>,--model <MODEL>: The model name (e.g.,gpt-4o-mini,o1-mini,claude-3-5-sonnet-20241022,gemini-2.5-pro,llama3.2).--provider <PROVIDER_PROFILE>: Choose a pre-configured provider profile from yourconfig.json'sprovidersmap.--list-models: List available models for the configured provider.
โ Fixed Issues:
- CLI API keys now properly set environment variables for the genai client
- Model validation works correctly before starting the UI
- Provider type selection is properly handled
- No more "API key only works as environment variable" issues
Run target/release/perspt --help for a full list.
๐ Usage Examples
OpenAI (including latest reasoning models):
# Latest GPT-4o-mini (fast and efficient)
# GPT-4.1 (enhanced capabilities)
# OpenAI o1-mini (reasoning model)
# OpenAI o1-preview (advanced reasoning)
# OpenAI o3-mini (latest reasoning model)
Google Gemini (including latest models):
# Gemini 2.0 Flash (latest fast model)
# Gemini 1.5 Pro (balanced performance)
Anthropic:
Groq (Ultra-fast inference):
# Llama models with lightning-fast inference
# Mixtral model
Cohere:
# Command-R+ (latest reasoning model)
# Command-R (balanced performance)
XAI (Grok):
DeepSeek:
# DeepSeek Chat
# DeepSeek Reasoner
Ollama (Local Models - No API Key Required!):
# First, make sure Ollama is running locally:
# ollama serve
# Llama 3.2 (3B - fast and efficient)
# Llama 3.1 (8B - more capable)
# Code Llama (for coding tasks)
# Mistral (7B - general purpose)
# Custom model (if you've imported one)
Using environment variables:
# Set once, use multiple times
# Now you can skip the --api-key argument
# Ollama doesn't need API keys
Using a config file:
(Ensure my_config.json is correctly set up with provider_type, api_key, and default_model).
๐ฏ Model Discovery & Validation
Perspt uses the modern genai crate for robust model handling and validation:
# List OpenAI models (including o1-mini, o1-preview, o3-mini, GPT-4.1)
# List Google models (including Gemini 2.5 Pro, 2.0 Flash)
# List Anthropic models
# List Groq models (ultra-fast inference)
# List Cohere models
# List XAI models
# List DeepSeek models
# List Ollama models (local, no API key needed)
โ Enhanced Model Support:
- Real Model Validation: Models are validated before starting the UI to prevent runtime errors
- Latest Model Support: Built on genai crate which supports cutting-edge models like o1-mini and Gemini 2.5 Pro
- Proper Error Handling: Clear error messages when models don't exist or aren't available
- Reasoning Model Support: Full support for models with reasoning capabilities and special event handling
๐ Using Ollama for Local Models
Ollama provides a fantastic way to run AI models locally on your machine without needing API keys or internet connectivity. This is perfect for privacy-conscious users, offline work, or simply experimenting with different models.
๐ ๏ธ Setting Up Ollama
-
Install Ollama:
# macOS # Linux | # Or download from: https://ollama.ai -
Start the Ollama service:
This starts the Ollama server at
http://localhost:11434 -
Download models:
# Llama 3.2 (3B) - Great balance of speed and capability # Llama 3.1 (8B) - More capable, slightly slower # Code Llama - Optimized for coding tasks # Mistral - General purpose model # Phi-3 - Microsoft's efficient model -
List available models:
๐ Using Ollama with Perspt
Once Ollama is running, you can use it with Perspt:
# Basic usage (no API key needed!)
# List available Ollama models
# Use different models
# With configuration file
๐ฏ Ollama Model Recommendations
| Model | Size | Best For | Speed | Quality |
|---|---|---|---|---|
llama3.2 |
3B | General chat, quick responses | โกโกโก | โญโญโญ |
llama3.1:8b |
8B | Balanced performance | โกโก | โญโญโญโญ |
codellama |
7B | Code generation, programming help | โกโก | โญโญโญโญ |
mistral |
7B | General purpose, good reasoning | โกโก | โญโญโญโญ |
phi3 |
3.8B | Efficient, good for resource-constrained systems | โกโกโก | โญโญโญ |
๐ง Ollama Troubleshooting
โ "Connection refused" errors:
# Make sure Ollama is running
# Check if it's responding
โ "Model not found" errors:
# List available models
# Pull the model if not available
โ Performance issues:
# Use smaller models for better performance
# Or check system resources
๐ Ollama Advantages
- ๐ Privacy: All processing happens locally, no data sent to external servers
- ๐ฐ Cost-effective: No API fees or usage limits
- โก Offline capable: Works without internet connectivity
- ๐๏ธ Full control: Choose exactly which models to run
- ๐ Easy model switching: Download and switch between models easily
๐๏ธ Architecture & Technical Features
Built on Modern genai Crate
Perspt is built using the genai crate (v0.3.5), providing:
-
๐ฏ Latest Model Support: Direct support for cutting-edge models including:
- OpenAI's o1-mini, o1-preview, o3-mini, and GPT-4.1 reasoning models
- Google's Gemini 2.5 Pro and Gemini 2.0 Flash
- Latest Claude, Mistral, and other provider models
-
โก Advanced Streaming: Proper handling of streaming events including:
ChatStreamEvent::Start- Response initiationChatStreamEvent::Chunk- Regular content chunksChatStreamEvent::ReasoningChunk- Special reasoning model chunksChatStreamEvent::End- Response completion
-
๐ก๏ธ Robust Error Handling: Comprehensive error management with:
- Network failure recovery
- API authentication validation
- Model compatibility checking
- Graceful panic recovery with terminal restoration
-
๐ง Flexible Configuration: Multiple configuration methods:
- CLI arguments (working properly!)
- Environment variables
- JSON configuration files
- Smart fallbacks and validation
Custom Markdown Parser
Perspt includes a custom-built markdown parser optimized for terminal rendering:
- Stream-optimized: Handles real-time streaming content efficiently
- Terminal-native: Designed specifically for terminal color capabilities
- Lightweight: No external dependencies, built for performance
- Robust: Handles partial and malformed markdown gracefully
- Buffer-managed: Intelligent buffering for smooth rendering during streaming
Key Technical Improvements
- Fixed CLI Arguments: API keys and model selection now work correctly via command line
- Enhanced Streaming: Improved buffering and event handling for smooth response rendering
- Better Authentication: Proper environment variable mapping for different providers
- Responsive UI: Reduced timeouts and improved responsiveness (50ms vs 100ms)
- Custom Markdown Rendering: Built-in parser eliminates external dependencies
- Comprehensive Documentation: Extensive code documentation and user guides
๐๏ธ Key Bindings
Enter: Send your input to the LLM or queue it if the LLM is busy.Esc: Exit the application safely with proper terminal restoration.Ctrl+C/Ctrl+D: Exit the application with graceful cleanup.Up Arrow/Down Arrow: Scroll through chat history smoothly.Page Up/Page Down: Fast scroll through long conversations.
โ UI Improvements:
- Faster response times with 50ms event timeouts
- Better streaming buffer management for smooth markdown rendering with custom parser
- Visual feedback during model processing
- Proper terminal restoration on all exit paths
๐ฅ Recent Major Updates (v0.4.0)
Migration to genai Crate
We've migrated from the allms crate to the modern genai crate (v0.3.5), bringing significant improvements:
๐ฏ Fixed Critical Issues:
- โ CLI Arguments Now Work: API keys, models, and provider types work correctly via command line
- โ Flexible Authentication: API keys work via CLI, environment variables, or config files
- โ Responsive UI: Fixed keystroke waiting issues - UI now responds immediately
- โ Custom Markdown Parser: Built-in markdown parser eliminates external dependencies
๐ New Features:
- Support for latest reasoning models (o1-mini, o1-preview, Gemini 2.5 Pro)
- Enhanced streaming with proper reasoning chunk handling
- Custom markdown parser optimized for terminal rendering
- Comprehensive error handling with terminal restoration
- Model validation before UI startup
- Extensive code documentation and user guides
๐ก๏ธ Reliability Improvements:
- Bulletproof panic handling that restores terminal state
- Network failure recovery
- Better error messages with troubleshooting tips
- Comprehensive logging for debugging
๐จ User Experience:
- Reduced response latency (50ms vs 100ms timeouts)
- Smoother markdown rendering with custom parser
- Better visual feedback during processing
- Improved chat history navigation
๐ง Troubleshooting
Common Issues & Solutions
โ "API key not found" or authentication errors:
# Method 1: Use CLI argument (recommended)
# Method 2: Set environment variable
# Method 3: Ollama doesn't need API keys
โ "Model not found" errors:
# List available models first
# Use exact model names from the list
โ Terminal corruption after crash:
# Reset terminal (if needed)
โ Permission denied errors:
# Make sure the binary is executable
# Or use cargo run for development
โ Documentation generation errors:
# If you see "Unrecognized option" errors when generating docs:
# The project includes custom rustdoc styling that's compatible with rustdoc 1.87.0+
โ Getting Help:
- Use
--helpfor full argument list:perspt --help - Check logs with:
RUST_LOG=debug perspt ... - Validate configuration with:
perspt --list-models - Test different providers to isolate issues
Best Practices
-
Always validate your setup first:
-
Use environment variables for security:
-
Start with simple models:
# These are reliable and fast -
Check the logs if issues persist:
RUST_LOG=debug
๐ CI/CD & Releases
This project uses GitHub Actions for comprehensive CI/CD:
๐งช Continuous Integration
- Multi-Platform Testing: Automated testing on Ubuntu, Windows, and macOS
- Code Quality: Automated formatting checks, clippy linting, and security audits
- Documentation: Automated building of both Rust API docs and Sphinx documentation
๐ฆ Automated Releases
- Cross-Platform Binaries: Automatic generation of optimized binaries for:
- Linux (x86_64)
- Windows (x86_64)
- macOS (x86_64 and ARM64)
- Documentation Packaging: Complete documentation bundles included in releases
- Checksum Generation: SHA256 checksums for all release artifacts
๐ Documentation Deployment
- GitHub Pages: Automatic deployment of documentation to GitHub Pages
- Dual Documentation: Both user guides (Sphinx) and API documentation (rustdoc)
- Live Updates: Documentation automatically updates on main branch changes
๐ฏ Getting Pre-built Binaries
Instead of building from source, you can download pre-built binaries from the releases page:
- Navigate to the latest release
- Download the appropriate binary for your platform
- Make it executable:
chmod +x perspt-*(Linux/macOS) - Move to your PATH:
sudo mv perspt-* /usr/local/bin/perspt
๐ Documentation
- Live Documentation: https://eonseed.github.io/perspt/
- User Guide: Comprehensive tutorials and usage examples
- API Documentation: Detailed Rust API documentation
๐ค Contributing
Contributions are welcome! Please open issues or submit pull requests for any bugs, features, or improvements.
Development Workflow
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Ensure CI passes locally:
cargo test && cargo clippy && cargo fmt --check - Submit a pull request
The CI will automatically test your changes on all supported platforms.
๐ License
Perspt is released under the GNU Lesser General Public License v3.0 (LGPL-3.0). See the LICENSE file for details.
โ๏ธ Author
- Vikrant Rathore
- Ronak Rathore
Perspt: Personal Spectrum Pertaining Thoughts โ the human lens through which we explore the enigma of AI and its implications for humanity.
