A multi-provider CLI assistant for interacting with AI models (OpenAI, Google Gemini).
Project description
AI CLI - Multi-Provider AI Assistant
A powerful and user-friendly command-line interface (CLI) to interact with various AI models, including OpenAI (GPT-3.5, GPT-4, GPT-4o) and Google Gemini (Gemini Pro, Gemini Flash). Built with Python using Typer, Rich, Questionary, and official provider libraries.
Overview
This CLI provides a seamless way to interact with Large Language Models (LLMs) directly from your terminal. It supports both interactive chat sessions with persistent history and direct non-interactive prompting across multiple AI providers.
Interactive Sessions: Start, resume, list, and delete persistent chat sessions. Features include automatic session naming, rich Markdown rendering for AI responses, file uploads with relative path context (enhanced with optional fzf/fd/bat/eza integration), token usage estimates, and various in-chat commands (including editing multi-line input via your preferred $EDITOR). You can specify providers/models per session or rely on configured defaults.
Direct Prompting: Get quick answers or generate content without entering an interactive session. Supports piping data via stdin, providing file context, choosing output formats (Markdown, raw text, JSON), saving results directly to files, and explicitly specifying the AI provider and model for the request. Token usage information is displayed on stderr after execution.
Features
- Multi-Provider Support: Seamlessly switch between different AI services (initially OpenAI & Google Gemini). Easily extendable.
- Flexible Configuration (
setupcommand):- Interactively configure API keys and select default models for each supported provider (
setup configure). - Set a global default provider to use when none is specified (
setup set-default). - View the current configuration, including masked API keys (
setup view). - Reads provider API keys from environment variables (
OPENAI_API_KEY,GOOGLE_API_KEY) or prompts securely if not found. - Configuration stored locally in
~/.ai-cli/config/config.json.
- Interactively configure API keys and select default models for each supported provider (
- Interactive Chat Sessions (
sessioncommand):- Start new sessions (
session new), optionally named (--name) or automatically named based on the first prompt. Specify provider/model with--provider/--modelto override defaults for that session. - Resume previous sessions via an interactive list (
session resume). Can also override provider/model when resuming. - List all saved sessions (
session list), sorted by modification time (latest first). - Delete one or more sessions via an interactive checklist (
session delete). - Persistent message history saved for each session in
~/.ai-cli/chat_sessions/.
- Start new sessions (
- Direct Prompting (
promptcommand):- Send a single prompt directly:
ai-cli prompt "Your question" - Specify provider/model:
ai-cli prompt "Ask Google..." --provider google - Pipe
stdin: Process piped data:cat file.txt | ai-cli prompt "Summarize:" - File Context: Provide a file as context:
ai-cli prompt "Explain code" -f script.py(Note:stdintakes precedence over-f). - Output Formats: Choose output:
markdown(default),raw,jsonusing--output-formator-of. - Save to File: Save the response directly:
ai-cli prompt "Generate code" -o code.py - Token Usage: Displays estimated token usage (prompt, completion, total) on stderr after completion.
- Send a single prompt directly:
- Rich Output: AI responses rendered using Markdown (default) for enhanced readability, including syntax highlighting for code blocks.
- File Handling (Interactive Session):
- Stage one or more files using
/upload [path]or just/upload(requiresfzfandfdfor interactive picker). - Files are included with relative path context in the prompt sent to the AI.
- File preview within
fzfenhanced by optionalbat(syntax highlighting) andeza(tree view for directories). - Check pending files (with relative paths) using
/status. - Clear all pending files before sending with
/clearfiles. - Prevents adding the exact same absolute file path multiple times.
- Configurable max file size (default: 50KB) and allowed extensions (defined in
constants.py).
- Stage one or more files using
- External Editor Support (Interactive Session):
- Use the
/editcommand to open your default editor (specified by$EDITOR) for composing multi-line input comfortably.
- Use the
- In-Chat Commands (Interactive Session):
/help: Show available commands (nicely formatted)./rename <new-name>: Rename the current session file./history: Display the conversation history for the current session./clear: Clear the history for the current session (requires confirmation)./upload [path]: Stage a file to be included in the next prompt./edit: Open$EDITORfor multi-line input./status: View staged files and their sizes./clearfiles: Remove all staged files without sending./usage: Show estimated token usage accumulated in the current session instance./exitor/quit: End the current chat session.
Installation
Prerequisites:
- Required:
- Python 3.8 or higher.
pip(Python package installer).- API keys for the desired AI providers (e.g., OpenAI, Google AI).
- Optional (Highly Recommended for Enhanced Features):
fzf: For interactive file selection with/upload. (Install Instructions)fd: Used byfzfintegration for fast file searching. (Install Instructions)bat: Provides syntax highlighting infzffile previews. (Install Instructions)eza: Provides tree view previews for directories infzf. (Install Instructions)- A configured
$EDITORenvironment variable (e.g.,vim,nano,code) for the/editcommand.
Installation Command:
pip install ai-assistant-multi
Installing Optional Dependencies
These tools significantly enhance the interactive experience. Install them using your system's package manager.
-
fzf(Fuzzy Finder):- macOS:
brew install fzf - Debian/Ubuntu:
sudo apt update && sudo apt install fzf - Fedora:
sudo dnf install fzf - Arch:
sudo pacman -S fzf - Windows (Scoop):
scoop install fzf| (Choco):choco install fzf - fzf GitHub
- macOS:
-
fd(fd-find - A simple, fast and user-friendly alternative to 'find'):- macOS:
brew install fd - Debian/Ubuntu:
sudo apt update && sudo apt install fd-find(Note: May install asfdfind. If so, symlink:ln -s $(which fdfind) ~/.local/bin/fd) - Fedora:
sudo dnf install fd-find - Arch:
sudo pacman -S fd - Windows (Scoop):
scoop install fd| (Choco):choco install fd - fd GitHub
- macOS:
-
bat(Cat clone with syntax highlighting):- macOS:
brew install bat - Debian/Ubuntu:
sudo apt update && sudo apt install bat(Note: May install asbatcat. If so, symlink:ln -s $(which batcat) ~/.local/bin/bat) - Fedora:
sudo dnf install bat - Arch:
sudo pacman -S bat - Windows (Scoop):
scoop install bat| (Choco):choco install bat - bat GitHub
- macOS:
-
eza(Modern replacement for ls):- macOS:
brew install eza - Debian/Ubuntu/Fedora/Arch: Check package managers or install from eza GitHub (binaries/cargo recommended).
- Windows (Scoop):
scoop install eza| (Choco):choco install eza
- macOS:
-
$EDITOREnvironment Variable: Ensure your system's$EDITORenvironment variable is set to your preferred command-line text editor. Add this to your shell configuration file (e.g.,.bashrc,.zshrc,.profile):export EDITOR=vim # Or nano, emacs, micro, helix, etc.
Reload your shell or run source ~/.your_shell_rc_file for the change to take effect.
Configuration
Before using the CLI, configure the AI providers you want to interact with.
-
Run the interactive configuration:
# If you created a link/alias: ai-cli setup configure # Or directly: python main.py setup configure
-
Follow the prompts:
- Select the providers (OpenAI, Google, etc.) you wish to set up.
- For each selected provider:
- The tool checks for existing API keys in environment variables (e.g.,
OPENAI_API_KEY) or the current config file. - If a key is found, you'll be asked to confirm or update it (input is hidden).
- If no key is found, you'll be prompted to enter it securely.
- You'll select a default model for that provider from a list.
- The tool checks for existing API keys in environment variables (e.g.,
- If multiple providers are configured, you'll be asked to choose a global default provider. This provider will be used when you don't explicitly specify one using the
--providerflag.
-
Set/Change the Default Provider Later (Optional):
ai-cli setup set-default
-
View Current Configuration:
ai-cli setup view
Your settings are saved in ~/.ai-cli/config/config.json.
Usage
Replace python main.py with your alias (e.g., ai-cli) if you set one up.
Interactive Sessions (session commands)
- Start New (using default provider):
ai-cli session new ai-cli session new --name "my-analysis"
- Start New (specifying provider/model):
ai-cli session new --provider google --model gemini-1.5-flash-latest ai-cli session new -p openai -m gpt-4o --name "gpt4o-chat"
- Resume Session (select from list):
ai-cli session resume # Resume but override the provider for this specific session run ai-cli session resume --provider openai
- List Sessions:
ai-cli session list
- Delete Sessions (select from list):
ai-cli session delete
Direct Prompting (prompt command)
-
Basic Prompt (using default provider):
ai-cli prompt "What are the main benefits of using Python?"
-
Specify Provider/Model:
ai-cli prompt "What's the weather like on Mars?" -p google ai-cli prompt "Write a short Rust function for bubble sort" -p openai -m gpt-4o
-
Using Piped Data (
stdin):cat data.csv | ai-cli prompt "Find the average value in the second column" git diff | ai-cli prompt "Summarize these code changes" -p openai
-
Using File Context (
-f):ai-cli prompt "Refactor this code for better readability" -f my_script.py # Note: If stdin is piped, the --file argument is ignored.
-
Specify Output Format (
-of):# Get raw text output ai-cli prompt "Generate five catchy taglines for a coffee shop" -of raw # Attempt to get JSON output ai-cli prompt "List the planets and their diameters as a JSON object" -of json -p google
-
Save Output to File (
-o):ai-cli prompt "Write a Python script to list files in a directory" -p openai -o list_files.py # Combine with other options (e.g., raw output to file) cat report.md | ai-cli prompt "Extract all action items into a bulleted list" -of raw -o action_items.txt
In-Chat Commands (during session new or session resume)
Type these commands directly into the chat prompt:
/help: Show this list of commands./rename <new-name>: Change the name of the current session./history: Display the conversation history./clear: Clear the conversation history (irreversible!)./upload [path]: Stage a file. Ifpathis omitted, attempts interactive selection (requiresfzf,fd)./edit: Open your$EDITORfor multi-line input./status: View files currently staged for the next prompt./clearfiles: Remove all staged files./usage: Show the estimated token count for the current session instance./exitor/quit: End the chat session.
Storage Locations
- Configuration File:
~/.ai-cli/config/config.json - Session History Files:
~/.ai-cli/chat_sessions/(Each session stored assession-name_uuid.json)
Contributing
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs, feature requests, or improvements.
(Optionally add more specific contribution guidelines here: e.g., coding style, testing requirements)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_assistant_multi-0.0.1.tar.gz.
File metadata
- Download URL: ai_assistant_multi-0.0.1.tar.gz
- Upload date:
- Size: 44.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09c65f3ab66294df602a541f1aa3f1c49bc79221f6932e01fffbaf72fee88be2
|
|
| MD5 |
d79948a729e4fb7b2feba0f84c262f00
|
|
| BLAKE2b-256 |
b7123d2bc7a564de86b9344761a66320dca6a1616e810c72b23801463fbdb5da
|
File details
Details for the file ai_assistant_multi-0.0.1-py3-none-any.whl.
File metadata
- Download URL: ai_assistant_multi-0.0.1-py3-none-any.whl
- Upload date:
- Size: 46.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f320a0488eced4b838ae7243eaa19f64a1fa4bacf2b5106e853fb06006d6c12
|
|
| MD5 |
6f95647334b82e52cb8efbba9286f76e
|
|
| BLAKE2b-256 |
e9353bd8b1a55f69fb20837028d0efc6a84ac2517ce24fbfb3a3fc7dc56356b1
|