Skip to main content

A modern REST API service for managing and serving AI prompts

Project description

๐Ÿš€ Exemplar Prompt Hub

Python Version FastAPI License Code Style Test Coverage PostgreSQL Docker

๐Ÿ“‘ Table of Contents

A modern REST API service for managing and serving AI prompts. This service provides a centralized repository for storing, versioning, and retrieving prompts for various AI applications. It uses PostgreSQL as the database for robust and scalable data management.

โœจ Features

For a detailed checklist of implemented and planned features, see FEATURES.md.

  • RESTful API for prompt management
  • Version control for prompts
  • Tag-based prompt organization
  • Metadata support for prompts
  • Authentication and authorization
  • Search and filtering capabilities

๐Ÿ› ๏ธ Getting Started

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)
  • Git
  • PostgreSQL (for database)
  • Docker and Docker Compose (for containerized setup)

Installation

Using pip

You can install the package directly from PyPI:

# Create and activate a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows, use `venv\Scripts\activate`

# Install the package
pip install exemplar-prompt-hub

# Copy the .env.example file to .env in your virtual environment
cp $(python -c "import site; print(site.getsitepackages()[0])")/exemplar_prompt_hub/.env.example .env

# Edit the .env file to configure your database and other settings

Or install from the source:

# Clone the repository
git clone https://github.com/yourusername/exemplar-prompt-hub.git
cd exemplar-prompt-hub

# Create and activate a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows, use `venv\Scripts\activate`

# Install the package
pip install -e .

# Copy .env.example to .env
cp .env.example .env

# Edit .env to configure your database and other settings

After installation, you can use the following command:

  • prompt-hub - Start the FastAPI server

Using Docker

The easiest way to get started is using Docker Compose:

  1. Clone the repository:

    git clone https://github.com/yourusername/exemplar-prompt-hub.git
    cd exemplar-prompt-hub
    
  2. Start the services:

    docker-compose up -d
    

    This will start:

  3. Access the services:

  4. Stop the services:

    docker-compose down
    

Manual Installation

If you prefer to run the services manually:

  1. Clone the repository:

    git clone https://github.com/yourusername/exemplar-prompt-hub.git
    cd exemplar-prompt-hub
    
  2. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows, use `venv\\Scripts\\activate`
    
  3. Install dependencies:

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

    • Copy .env.example to .env:
      cp .env.example .env
      
    • Edit .env to configure your database and other settings.
  5. Start the application:

    uvicorn app.main:app --reload
    

Running Tests

To run the tests, use:

pytest

For detailed test coverage, use:

pytest --cov=app --cov-report=term-missing

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For detailed contribution guidelines, please refer to the CONTRIBUTING.md file.

License

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

๐Ÿ“š API Documentation

Once the server is running, you can access the interactive API documentation at:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

๐Ÿ”„ API Usage Examples

Here are some example curl commands to interact with the API:

Create a Prompt

curl -X POST "http://localhost:8000/api/v1/prompts/" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "example-prompt",
    "text": "This is an example prompt text",
    "description": "A sample prompt for demonstration",
    "version": 1,
    "meta": {
      "author": "test-user",
      "category": "example"
    },
    "tags": ["example", "test"]
  }'

Get All Prompts

# Get all prompts
curl "http://localhost:8000/api/v1/prompts/"

# Get prompts with search
curl "http://localhost:8000/api/v1/prompts/?search=example"

# Get prompts with tag filter
curl "http://localhost:8000/api/v1/prompts/?tag=test"

# Get prompts with pagination
curl "http://localhost:8000/api/v1/prompts/?skip=0&limit=10"

Get a Specific Prompt

# Replace {prompt_id} with actual ID
curl "http://localhost:8000/api/v1/prompts/{prompt_id}"

Update a Prompt

curl -X PUT "http://localhost:8000/api/v1/prompts/{prompt_id}" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Updated prompt text",
    "description": "Updated description",
    "meta": {
      "author": "test-user",
      "category": "updated"
    },
    "tags": ["updated", "test"]
  }'

Delete a Prompt

curl -X DELETE "http://localhost:8000/api/v1/prompts/{prompt_id}"

๐Ÿ“ Project Structure

exemplar-prompt-hub/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ””โ”€โ”€ endpoints/
โ”‚   โ”‚       โ””โ”€โ”€ prompts.py
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”‚   โ””โ”€โ”€ config.py
โ”‚   โ”œโ”€โ”€ db/
โ”‚   โ”‚   โ”œโ”€โ”€ base_class.py
โ”‚   โ”‚   โ”œโ”€โ”€ models.py
โ”‚   โ”‚   โ””โ”€โ”€ session.py
โ”‚   โ”œโ”€โ”€ schemas/
โ”‚   โ”‚   โ””โ”€โ”€ prompt.py
โ”‚   โ””โ”€โ”€ main.py
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ test_prompts.py
โ”œโ”€โ”€ alembic/
โ”‚   โ””โ”€โ”€ versions/
โ”œโ”€โ”€ .env.example
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ MANIFEST.in
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ setup.py

๐Ÿ“Š Database Table Structure

Prompts Table

CREATE TABLE prompts (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    text TEXT NOT NULL,
    description TEXT,
    version INTEGER NOT NULL,
    meta JSONB,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP WITH TIME ZONE
);

Tags Table

CREATE TABLE tags (
    id SERIAL PRIMARY KEY,
    name VARCHAR(50) NOT NULL UNIQUE
);

Prompt Tags Table (Many-to-Many Relationship)

CREATE TABLE prompt_tags (
    prompt_id INTEGER REFERENCES prompts(id) ON DELETE CASCADE,
    tag_id INTEGER REFERENCES tags(id) ON DELETE CASCADE,
    PRIMARY KEY (prompt_id, tag_id)
);

๐Ÿ”„ Updating Prompts with Versioning

The API supports versioning of prompts. When updating a prompt:

  1. The current version is incremented
  2. A new record is created with the updated content
  3. The old version is preserved for reference

To update a prompt, use the PUT endpoint with the prompt ID:

curl -X PUT "http://localhost:8000/api/v1/prompts/{prompt_id}" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Updated prompt text",
    "description": "Updated description",
    "meta": {
      "author": "test-user",
      "category": "updated"
    },
    "tags": ["updated", "test"]
  }'

The API will automatically handle versioning and maintain the history of changes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

exemplar_prompt_hub-0.1.9.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

exemplar_prompt_hub-0.1.9-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file exemplar_prompt_hub-0.1.9.tar.gz.

File metadata

  • Download URL: exemplar_prompt_hub-0.1.9.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for exemplar_prompt_hub-0.1.9.tar.gz
Algorithm Hash digest
SHA256 0201805fd4ba30ac485340e60feb37db56c111bb37a9105d23619e15f56aea5d
MD5 41db6fba092c26b73b9433f8a6e9f5ab
BLAKE2b-256 c8d088aac57c36853959bc8b69d15eb64d94f1e575c7ced8ae1e7c6680ad4539

See more details on using hashes here.

File details

Details for the file exemplar_prompt_hub-0.1.9-py3-none-any.whl.

File metadata

File hashes

Hashes for exemplar_prompt_hub-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 9304db37c4a78a081f95f63926fb15d3b5c72aae3845cba4e8984e833bcb999e
MD5 21f5b30de5d0e1171932c8f421a27e41
BLAKE2b-256 0d9e455ccffea6c895fcf0a1c70a393798b8d20ae11f5d4e4fc59fca47fb0cff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page