AI-powered prompt optimization agent. Input a rough prompt, get back a polished, structured version ready for production use.
The optimizer runs a 6-stage pipeline:
- Input -- paste your raw prompt
- Analyze -- AI identifies intent, strengths, and weaknesses
- Template Match -- selects the best prompt engineering pattern (role-play, chain-of-thought, few-shot, etc.)
- Clarify -- asks targeted questions to fill gaps in your intent
- Generate -- produces multiple optimized candidates, scores them, and picks the best one
- Result -- bilingual output (Chinese + English) with one-click copy and download
- Multi-candidate generation with automatic scoring and selection
- 9 built-in prompt templates: role-play, chain-of-thought, few-shot, structured output, task decomposition, constraint-based, meta-prompting, image generation, video generation, agent/tool calling
- Built-in example library for few-shot injection
- Custom template support via sidebar
- Bilingual translation with quality verification
- Optimized prompt history with file export (Markdown)
- Configurable LLM backend: Anthropic or OpenAI-compatible APIs
- Streaming output for long generations
- Python 3.10+
- An API key for Anthropic or an OpenAI-compatible provider
pip install -r requirements.txtCreate a .env file in the project root:
# For Anthropic (default)
ANTHROPIC_API_KEY=sk-ant-xxx
ANTHROPIC_BASE_URL=https://api.anthropic.com # optional
ANTHROPIC_MODEL=claude-sonnet-4-20250514 # optional
# For OpenAI-compatible providers
OPENAI_API_KEY=sk-xxx
OPENAI_BASE_URL=https://api.openai.com # or any compatible endpoint
OPENAI_MODEL=gpt-4o # optionalstreamlit run app.pyThe app opens at http://localhost:8501. You can also configure the API key, base URL, and model directly in the sidebar.
.
├── app.py # Streamlit entry point
├── config/
│ ├── settings.py # Global settings (model, temperature, retries)
│ ├── templates.py # 9 built-in prompt engineering templates
│ ├── examples.py # Pre-built optimization examples
│ └── logging_config.py # Logging setup
├── core/
│ ├── analyzer.py # Stage 2: prompt analysis
│ ├── template_matcher.py # Stage 3: template matching
│ ├── questioner.py # Stage 4: clarifying questions
│ ├── generator.py # Stage 5: candidate generation + scoring + translation
│ ├── llm_client.py # LLM API wrapper (Anthropic/OpenAI, retry, streaming)
│ └── prompt_loader.py # System prompt file loader
├── prompts/ # System prompt templates (.txt)
├── ui/
│ ├── pages.py # Stage-based page rendering (state machine)
│ ├── components.py # Reusable UI components
│ └── sidebar.py # Sidebar config panel
├── utils/
│ ├── file_handler.py # Markdown export and download helpers
│ └── validators.py # Input validation
└── scripts/
└── sync_prompts.py # Sync .txt prompts to HTML embedded constants
| Setting | Default | Description |
|---|---|---|
DEFAULT_API_TYPE |
anthropic |
LLM provider |
DEFAULT_MODEL |
mimo-v2.5-pro |
Default model name |
DEFAULT_NUM_CANDIDATES |
3 |
Number of candidates to generate |
MAX_RETRIES |
5 |
API call retry count |
RETRY_BASE_DELAY |
3 |
Base delay (seconds) for exponential backoff |
Temperature per stage is tuned independently (0.2--0.4) in config/settings.py.
prompt_optimizer.html is a self-contained single-file version with the same functionality -- no server required, just open in a browser and enter your API key. Use scripts/sync_prompts.py to keep the HTML's embedded prompts in sync with the .txt files.
MIT