Services Blog Français

Introducing prompt2: The Ultimate AI-Powered CLI Tool

| by jpic | cli ai prompt2 dev

Are you ready to revolutionize your command-line experience? Say hello to prompt2, the cutting-edge software that brings the power of AI directly to your terminal. Whether you’re a developer, a sysadmin, or just a tech enthusiast, prompt2 is here to supercharge your productivity and creativity.

Why prompt2?

  • Prompt Engineering Playground 🎮: Iterate and refine your prompts faster than you can say “ChatGPT”. prompt2 gives you the tools to experiment and perfect your AI interactions.
  • Terminal Native 🖥️: Designed for the keyboard warriors who live in their terminals. Feel right at home with a CLI that speaks your language.
  • Jinja2 Turbocharged ✨: Harness the power of Jinja2 templating with magic variables like {{reads}}, {{writes}}, and custom filters to create dynamic, powerful prompts.
  • Cache Commander 💸: Save on API costs with automatic response caching, reducing expenses by over 40%.
  • Plugin Ecosystem 🔌: Extend prompt2 with ease using Python’s simple plugin system. Add custom backends, parsers, and filters to tailor the tool to your needs.

Getting Started with prompt2

Ready to dive in? Here’s how to get started:

pip install prompt2
export OPENROUTER_API_KEY=sk_...
prompt2 edit hello
prompt2 send hello

With these simple commands, you’ll be crafting and sending AI-powered prompts in no time. And remember, prompt2 puts you in control of the narrative.

Note: If you’re using LiteLLM, you can use any supported ENV vars instead of OPENROUTER_API_KEY.

Hands-On Tutorial

Let’s walk through a quick tutorial to see prompt2 in action:

  1. Create a Prompt: Run prompt2 edit hello. This opens your $EDITOR, where you can type something like create a hello world in python. This creates a prompt in ~/.prompt2/prompts/hello.txt, which you can view with prompt2 list.

  2. Send the Prompt: Run prompt2 send hello. Watch as the AI responds with a tutorial on creating a Python script.

  3. Use a Parser: Run prompt2 send hello wholefile to use the wholefile parser. You’ll get only the Python source code as output.

  4. Save the Output: Run prompt2 send hello wholefile > hello.py. Notice how prompt2 caches responses to save costs, making subsequent runs lightning-fast.

  5. Update the Prompt: Run prompt2 edit hello again, and update the text to:

    update this script to also print any sys arg with the hello string {{read('hello.py')}}
    

    This uses Jinja2 to read the content of hello.py and include it in the prompt. You can even register your own Jinja functions and template paths!

  6. Send the Updated Prompt: Run prompt2 send hello wholefile > hello.py again to update your script.

  7. Profit: Enjoy your newly enhanced script!

Troubleshooting

If you run into any issues, you can peek behind the curtain with:

DEBUG=1 prompt2 send hello

Models and Configuration

prompt2 supports multiple models through environment variables. Set MODEL to configure your default LLM plugin:

MODEL='openrouter/google/gemini-2.5-pro-exp-03-25:free'

You can also define specific models for different purposes:

MODEL_EDITOR='deepseek/deepseek-chat:free max_tokens=16384'
MODEL_ARCHITECT=xai/grok-2-latest

Python API

For those who love scripting, prompt2 offers a Python API:

import prompt2
import asyncio

async def ai_wizard():
    model = prompt2.Model.get('architect')
    prompt = prompt2.Prompt('hello')
    result = await model(prompt, 'wholefile')
    with open('hello.py', 'w') as f:
        f.write(result)

asyncio.run(ai_wizard())

Plugins

prompt2’s plugin system is robust and flexible:

  • Parsers: Modify messages before sending and parse responses into Python variables.
  • Jinja2: Add custom functions to your templates.
  • Backends: Integrate custom AI APIs, perfect for air-gapped networks.

CLI Reference

Here’s a quick overview of prompt2’s CLI commands:

  • prompt2 paths: Return prompt paths.
  • prompt2 list: List available prompts.
  • prompt2 edit NAME: Edit a prompt.
  • prompt2 show PROMPT: Show a prompt.
  • prompt2 render PROMPT CONTEXT=VALUE...: Render a prompt with a given template context.
  • prompt2 parser NAME: Show a parser.
  • prompt2 parsers: List registered parsers.
  • prompt2 messages PROMPT [parser=PARSER] [model=MODEL] [CONTEXT=VALUE]...: Render prompt messages.
  • prompt2 send PROMPT [parser=PARSER] [model=MODEL] [CONTEXT=VALUE]...: Send a prompt and get a response.

Why prompt2 Over aider-chat?

While aider-chat has its merits, prompt2 was built to address specific needs:

  • Flexibility with APIs: prompt2 supports custom APIs and plugins, unlike aider-chat’s heavy reliance on litellm.
  • CLI Focus: prompt2 embraces the classic CLI experience, avoiding the complexities of prompt-toolkit.
  • Control Over Commits: prompt2 lets you manage your version control flow, unlike aider-chat’s automatic commits.
  • Customizable Style: With cli2.theme, prompt2 offers extensive theming options.
  • Light Configuration: prompt2 uses environment variables and CLI tweaks, avoiding heavy configuration files.
  • Project Independence: Work with code anywhere, not just within git projects.

In essence, prompt2 is designed for those who crave simplicity, control, and the ability to tailor their tools to their exact needs. Give it a try and see how it transforms your CLI experience!


With prompt2, the power of AI is at your fingertips, ready to enhance your terminal workflow like never before. Happy prompting!

Read The Friendly Documentation

They trust us

Contact

logo