Skip to content

LISA-ITMO/promptab

Repository files navigation

PrompTab

Intelligent Chrome extension for prompt optimization using AI techniques including RAG, Chain-of-Thought, Role-playing, Few-shot learning and other.

Features

Core Functionality

  • Intelligent Prompt Optimization: Automatic prompt improvement using AI techniques
  • RAG System: Retrieval-Augmented Generation with vector knowledge base
  • Interactive Variables: Create and manage variables in prompts for reusability
  • Template Library: Save and organize frequently used prompts
  • Direct Integration: Send optimized prompts to ChatGPT and Perplexity
  • Multilingual Support: Russian and English languages

Advanced AI Techniques

  • Chain-of-Thought: Step-by-step reasoning for complex prompts
  • Role-playing: Context-aware persona-based optimization
  • Few-shot Learning: Example-based prompt enhancement
  • Vector Search: Semantic similarity for relevant examples
  • Context Awareness: Intelligent context preservation

Architecture

Backend Stack

  • Framework: FastAPI (Python 3.11+)
  • Database: PostgreSQL 14+ with pgvector extension
  • Vector Store: Sentence Transformers + pgvector
  • LLM Integration: OpenAI, Perplexity, Ollama
  • Caching: Redis for performance optimization
  • Authentication: JWT-based security
  • Monitoring: Prometheus + Grafana
  • Container: Docker + Docker Compose

Frontend Stack

  • Framework: React 18 + TypeScript
  • Build System: Webpack 5 with optimization
  • UI Library: Material-UI (MUI) v5
  • State Management: React Query for server state
  • Internationalization: i18next
  • Extension: Chrome Extension Manifest V3
  • Testing: Jest + React Testing Library

Infrastructure

  • Database: PostgreSQL with pgvector for embeddings
  • Cache: Redis for session and data caching
  • LLM Services: Multiple AI provider integrations
  • Monitoring: Prometheus metrics + Grafana dashboards
  • Reverse Proxy: Nginx for production deployment
  • Local LLM: Ollama for open-source model support

Installation

Prerequisites

  • Docker and Docker Compose
  • Node.js 18+ (for frontend development)
  • Python 3.11+ (for backend development)
  • PostgreSQL 14+ with pgvector extension
  • Redis 7+

Quick Start with Docker

  1. Clone the repository
git clone https://github.com/LISA-ITMO/promptab.git
cd promptab
  1. Configure environment variables
cp .env.example .env
# Edit .env with your API keys and configuration
  1. Start all services
docker-compose up -d
  1. Install Chrome extension
  • Open Chrome and go to chrome://extensions/
  • Enable "Developer mode"
  • Click "Load unpacked extension"
  • Select the frontend/dist folder

Manual Setup

Backend Setup

cd backend
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt
pip install -r requirements-docs.txt

# Run database migrations
alembic upgrade head

# Start development server
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Frontend Setup

cd frontend
npm install

# Development mode
npm start

# Build for production
npm run build

# Package extension
npm run package

Configuration

Environment Variables

Create .env file in the root directory:

# Database
POSTGRES_DB=promptab
POSTGRES_USER=promptab_user
POSTGRES_PASSWORD=your_password
DATABASE_URL=postgresql://promptab_user:your_password@localhost:5432/promptab

# Redis
REDIS_URL=redis://localhost:6379

# LLM API Keys
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key
PERPLEXITY_API_KEY=your_perplexity_key

# Security
SECRET_KEY=your_secret_key
JWT_ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30

# Monitoring
SENTRY_DSN=your_sentry_dsn
PROMETHEUS_PORT=9090

# Ollama (Local LLM)
OLLAMA_BASE_URL=http://localhost:11434

API Configuration

The backend provides RESTful API endpoints:

  • Authentication: /api/auth/
  • Prompts: /api/prompts/
  • Templates: /api/templates/
  • Variables: /api/variables/
  • Optimization: /api/optimize/
  • Health Check: /health

Testing

Backend Tests

cd backend

# Run all tests
pytest

# Run with coverage
pytest --cov=app --cov-report=html

# Run specific test categories
pytest tests/test_api_prompts.py
pytest tests/test_services.py
pytest tests/test_models.py

Documentation

Backend Documentation

  • Live Documentation: GitHub Pages
  • API Reference: Complete API documentation with examples
  • Architecture Guide: Detailed system architecture and design decisions
  • Development Guide: Setup and development workflow

Building Documentation Locally

# Backend documentation
cd backend
./scripts/build_docs.sh

# View locally
cd docs/_build/html
python -m http.server 8000

CI/CD Pipeline

GitHub Actions Workflows

  1. Documentation Pipeline (.github/workflows/docs.yml)
    • Automatic Sphinx documentation build
    • Quality checks and validation
    • Deployment to GitHub Pages

Quality Assurance

  • Code Quality: ESLint, Prettier, Black, Ruff
  • Type Checking: TypeScript, MyPy
  • Security: Bandit, Safety
  • Performance: Bundle analysis, load testing

Development

Project Structure

promptab/
├── backend/                 # FastAPI backend
│   ├── app/
│   │   ├── api/            # API endpoints
│   │   ├── core/           # Core configuration
│   │   ├── db/             # Database models
│   │   ├── models/         # Pydantic models
│   │   ├── schemas/        # API schemas
│   │   └── services/       # Business logic
│   ├── docs/               # Sphinx documentation
│   ├── tests/              # Backend tests
│   └── scripts/            # Build and utility scripts
├── frontend/               # React Chrome extension
│   ├── src/
│   │   ├── components/     # React components
│   │   ├── hooks/          # Custom React hooks
│   │   ├── services/       # API services
│   │   ├── utils/          # Utility functions
│   │   ├── popup/          # Extension popup
│   │   ├── options/        # Extension options
│   │   ├── background/     # Background scripts
│   │   └── contentScript/  # Content scripts
│   ├── scripts/            # Build scripts
│   └── dist/               # Built extension
├── docker/                 # Docker configurations
├── docs/                   # Project documentation
└── .github/                # GitHub Actions workflows

Contributing

Development Workflow

  1. Fork the repository
  2. Create a feature branch
git checkout -b feature/your-feature-name
  1. Make your changes
  2. Run tests and linting
# Backend
cd backend && pytest && black app/ && ruff check app/

# Frontend
cd frontend && npm test && npm run lint
  1. Commit your changes
git commit -m "feat: add your feature description"
  1. Push and create a pull request

Code Standards

  • Backend: Follow PEP 8, use type hints, add docstrings
  • Frontend: Follow ESLint rules, use TypeScript, add JSDoc
  • Testing: Maintain >80% code coverage
  • Documentation: Update docs for new features

Security

Security Features

  • Authentication: JWT-based secure authentication
  • Authorization: Role-based access control
  • Input Validation: Comprehensive input sanitization
  • Rate Limiting: API rate limiting and abuse prevention
  • HTTPS: Secure communication protocols
  • Secrets Management: Environment-based configuration

Security Best Practices

  • Regular dependency updates
  • Security scanning in CI/CD
  • Input validation and sanitization
  • Proper error handling
  • Secure session management

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Support


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors