Skip to content

About

AI提示词优化器,将你的提示词优化为AI使用起来更高效的形状

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

Prompt Optimizer

中文版

AI-powered prompt optimization agent. Input a rough prompt, get back a polished, structured version ready for production use.

What It Does

The optimizer runs a 6-stage pipeline:

  1. Input -- paste your raw prompt
  2. Analyze -- AI identifies intent, strengths, and weaknesses
  3. Template Match -- selects the best prompt engineering pattern (role-play, chain-of-thought, few-shot, etc.)
  4. Clarify -- asks targeted questions to fill gaps in your intent
  5. Generate -- produces multiple optimized candidates, scores them, and picks the best one
  6. Result -- bilingual output (Chinese + English) with one-click copy and download

Features

  • 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

Quick Start

Prerequisites

  • Python 3.10+
  • An API key for Anthropic or an OpenAI-compatible provider

Install

pip install -r requirements.txt

Configure

Create 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                              # optional

Run

streamlit run app.py

The app opens at http://localhost:8501. You can also configure the API key, base URL, and model directly in the sidebar.

Project Structure

.
├── 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

Configuration

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.

Standalone HTML Version

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.

License

MIT

About

AI提示词优化器,将你的提示词优化为AI使用起来更高效的形状

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages