Skip to main content

Prompt to pipe

Project description

A command-line tool that lets you pipe input into customizable AI prompts.

Example Usage

# Generate a commit message from staged changes
git diff --staged | p2p create-commit-message

# Example explanation of the above command
# This command takes the output of `git diff --staged` and pipes it into the `p2p` tool
# to generate a commit message based on the changes.

Example Output

refactor: reorder imports in cli.py and update flake8 select list

- Reorganize the import order in `pipe2prompt/cli.py` for better readability.
- Remove the `isort` ("I") code from the flake8 select list in `pyproject.toml`.

Installation

To install the package, you can use pip:

pip install pipe2prompt

To install from source:

git clone https://github.com/digsy89/pipe2prompt
cd pipe2prompt
pip install --user .

This will:

  1. Install the package locally with pip

  2. Set up shell completion

  3. Create initial config file at ~/.p2p/config.toml

OpenAI API Key

This tool requires an OpenAI API key to function. You can set it up in two ways:

export OPENAI_API_KEY=your-api-key-here

Shell Completion

To manually set up completion:

p2p init

This will:

  1. Create completion scripts in your shell’s completion directory

  2. Add source commands to your shell config file

  3. Enable tab completion for p2p commands and prompts

Supported shells:

  • Bash (~/.bash_completion.d/_p2p)

  • Zsh (~/.zsh/completions/_p2p)

  • Fish (~/.config/fish/completions/_p2p)

After installation, you may need to restart your shell or source your config file:

# For bash
source ~/.bashrc

# For zsh
source ~/.zshrc

# For fish
source ~/.config/fish/config.fish

Usage

Basic usage:

# Run a prompt directly
p2p <prompt-name> "your input"

# Pipe input into a prompt
echo "your input" | p2p <prompt-name>

# List available prompts
p2p prompt list
p2p prompt list --long

Prompt Configuration

Prompts are configured in ~/.p2p/config.toml. Example configuration:

[explain]
content = "Explain this code: {pipe}"
base_model = "gpt-3.5-turbo"
description = "Explain code"

[fix]
content = "Fix this code and explain the issues: {pipe}"
base_model = "gpt-3.5-turbo"
description = "Fix code issues"

Each prompt requires:

  • content: The prompt template. Use {pipe} to reference piped input

  • base_model: The OpenAI model to use

  • description: Description shown in help text

  • enabled: Optional boolean to enable/disable the prompt

You can find example configurations in the project’s [pipe2prompt/config.toml](pipe2prompt/config.toml) file for reference.

License

MIT

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page