Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

landscape - prompt critic and optimizer

Prompt Critic & Optimizer

An AI-powered developer tool that analyzes, critiques, and improves your prompts. Built with production-quality engineering practices: modular architecture, separation of concerns, and clean extensibility.

What It Does

Give PromptForge any prompt and it returns:

  • Intent — What the prompt is trying to achieve
  • Issues — Problems with clarity, missing context, or structure
  • Improved Prompt — A rewritten, optimized version
  • Score — Quality rating from 1–10 with justification
  • Before vs After — Side-by-side comparison of original and improved prompt

Core AI Concepts

Concept How It's Used
System Prompt Defines PromptForge's behavior as a prompt engineering expert
Few-Shot Prompting Provides example critiques for consistent, high-quality output
Basic RAG Injects prompt engineering best practices as context
Structured Output Returns intent, issues, and improved prompt in a parseable format

Tech Stack

  • Python — Core language
  • OpenAI API — LLM backbone (GPT-4o-mini by default)
  • Gradio — Web UI for interactive prompt optimization

Project Structure

prompt-critic-and-optimizer/
├── app.py                  # Entry point — launches the Gradio UI
├── requirements.txt        # Python dependencies
├── .env.example            # Environment variable template
├── .gitignore
│
├── config/
│   └── settings.py         # Centralized configuration & env loading
│
├── prompts/
│   ├── system_prompt.py    # System prompt defining AI behavior
│   └── few_shot.py         # Few-shot examples for output consistency
│
├── rag/
│   └── knowledge_base.py   # Prompt best practices injected as context
│
├── services/
│   ├── llm_service.py      # OpenAI API wrapper
│   └── pipeline.py         # Orchestration: analyze → critique → improve
│
└── utils/
    └── parser.py           # Output parsing & validation helpers

Getting Started

Prerequisites

Installation

  1. Clone the repository

    git clone https://github.com/hasnaat-iftikhar/prompt-critic-and-optimizer.git
    cd prompt-critic-and-optimizer
  2. Create a virtual environment (recommended)

    python -m venv venv
    source venv/bin/activate        # macOS/Linux
    venv\Scripts\activate           # Windows
  3. Install dependencies

    pip install -r requirements.txt
  4. Set up environment variables

    cp .env.example .env

    Open .env and add your OpenAI API key:

    OPENAI_API_KEY=sk-your-actual-key-here
    OPENAI_MODEL=gpt-4o-mini
    

Running the App

python app.py

The app will start at http://127.0.0.1:7860 — open it in your browser.

Configuration

All settings are managed through environment variables (loaded from .env):

Variable Default Description
OPENAI_API_KEY Your OpenAI API key (required)
OPENAI_MODEL gpt-4o-mini Model to use for analysis
MAX_TOKENS 2048 Maximum tokens in LLM response
TEMPERATURE 0.7 Creativity level (0.0 = focused, 1.0 = creative)

Architecture

User Input (prompt)
       │
       ▼
┌─────────────────┐
│   Gradio UI      │   UI layer — input, results, before/after tabs
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│    Pipeline      │   Orchestrates the full analysis flow
└────────┬────────┘
         │
    ┌────┴─────────────────┐
    │                      │
    ▼                      ▼
┌──────────┐    ┌─────────────────┐
│ Prompts  │    │  RAG Knowledge  │   Context & examples
│ (system  │    │  Base (best     │
│  + few-  │    │   practices)    │
│  shot)   │    │                 │
└────┬─────┘    └────────┬────────┘
     │                   │
     └─────────┬─────────┘
               │
               ▼
       ┌──────────────┐
       │  LLM Service │   OpenAI API call
       │  (OpenAI)    │
       └──────┬───────┘
              │
              ▼
       ┌──────────────┐
       │    Parser     │   Extracts structured sections
       └──────┬───────┘
              │
              ▼
       Structured Output
       (Intent, Issues, Improved Prompt, Score)

License

This project is for educational and development purposes.

About

An AI-powered developer tool that analyzes, critiques, and improves your prompts. Built with production-quality engineering practices: modular architecture, separation of concerns, and clean extensibility.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages