Promptify is an end-to-end automatic prompt generation and optimization system designed to select the best reasoning style (e.g., Chain-of-Thought vs Roleplay) for a given task description. It integrates machine learning, NLP, and prompt engineering into a seamless workflow — from classification to text generation.
Promptify intelligently decides how an LLM should think before generating text.
When given a user prompt, the system:
- Classifies the prompt as either:
- Chain-of-Thought (CoT) – suited for analytical or reasoning-based tasks.
- Roleplay – suited for conversational, creative, or persona-driven tasks.
- Generates text using a Flan-T5 model equipped with LoRA adapters, one fine-tuned for each reasoning style.
This allows the model to dynamically switch between different "thinking modes," improving output quality and adaptability across various prompt types.
| Layer | Description |
|---|---|
| Frontend | Built with React + Vite for a clean, responsive UI. Users can enter prompts, view classifications, and visualize generated outputs. The frontend communicates with the backend through a development proxy. |
| Backend | Implemented using FastAPI, it exposes REST endpoints for classification and text generation. It loads: - A DistilBERT classifier that determines the appropriate adapter. - A Flan-T5 model with two LoRA adapters ( cot and roleplay) for task-specific generation. |
| Training Scripts | Python utilities for: - Fine-tuning LoRA adapters on Chain-of-Thought and Roleplay datasets. - Training the DistilBERT classifier to label incoming prompts by type. |
- User Input: A prompt is submitted via the frontend.
- Classification: The backend classifier predicts the best adapter (
cotorroleplay). - Generation: The selected adapter is applied to the base Flan-T5 model.
- Response: The generated output is returned and displayed in the UI.
- Backend: FastAPI, Transformers, PEFT, PyTorch
- Frontend: React, Vite
- Models: Flan-T5 (with LoRA adapters), DistilBERT classifier
- Training: Custom in-house datasets (CSV), LoRA fine-tuning utilities
backend/
main.py # FastAPI server
requirements.txt # API-focused deps
adapters/
cot/ # CoT LoRA adapter folder (tokenizer + adapter files)
roleplay/ # Roleplay LoRA adapter folder
classifier/ # Exported HF text-classification model (tokenizer + safetensors)
frontend/
... # React + Vite app
scripts/
train_cot.py # Train CoT adapter
train_roleplay.py # Train Roleplay adapter
train_classifier.py # Train classifier (DistilBERT)
test_*.py # Quick inference checks
data/
... # CSVs used by the training scripts
requirements.txt # Unified deps (API + training)
- Python 3.10+
- Node.js 18+
- If using GPU: install the correct PyTorch CUDA build for your system.
Install all Python deps from the repository root (covers API + training):
pip install -r requirements.txtInstall frontend deps:
cd frontend
npm installFrom the backend/ folder:
uvicorn main:app --host 0.0.0.0 --port 8000 --reloadHealth check:
curl http://localhost:8000/healthGET /health→{ "status": "ok" }POST /classify→ body:{ "prompt": string }→{ "label": "cot" | "roleplay" }POST /generate→ body:{ "prompt": string, "adapter_override"?: "cot"|"roleplay" }→{ "adapter", "output" }
Generation uses the exact, deterministic beam settings from the test scripts for reproducibility.
The Vite dev server proxies /api/* to the backend on port 8000.
cd frontend
npm run devThen open the printed localhost URL (typically http://localhost:5173). Requests to /api will be forwarded to http://localhost:8000.
- CPU vs GPU: The backend auto-selects GPU if available via
torch.cuda.is_available(). On CPU-only systems, this is fine but slower. - PyTorch install: If you need CUDA-enabled PyTorch, follow the official install matrix and replace the
torchwheel accordingly. - Tokenizer files: Ensure adapter directories include
tokenizer.json/tokenizer_config.jsonand any special tokens to match training. - SentencePiece: Required for T5 tokenization; included in requirements.
This repository is provided as-is for demonstration and research. Review model licenses for any pretrained weights you use.