Open Crucible is a playground for experimenting with prompt injections and understanding how different prompt components interact with language models. Built with FastAPI and powered by Hugging Face Transformers, this project provides a web interface to test and visualize how system prompts, user prompts, and tokenization influence model outputs.
- Customizable Prompts: Combines a hard-coded system prompt with user-provided input in a structured format.
- Token Visualization: Displays tokenized representations of both user input and model output.
- Web Interface: Interactive HTML frontend to experiment with prompt injections.
-
models.py
Loads the tokenizer and model, sets up special tokens (including a custom pad token), and configures the model. -
routes.py
Defines API endpoints using FastAPI. The/generateendpoint constructs a combined prompt (system + user) and generates text, while the root endpoint serves the HTML interface. -
main.py
The FastAPI application entrypoint. It includes the routes and runs the server using Uvicorn. -
schemas.py
Contains Pydantic models for request validation, such as theGenerationRequest.
- Python 3.8 or higher
- PyTorch (with CUDA support if you want GPU acceleration)
- FastAPI
- Uvicorn
- Transformers
- Other dependencies (see
requirements.txtif provided)
-
Clone the Repository:
git clone https://github.com/stackviolator/open-crucible.git cd open-crucible -
Create a venv
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install Dependencies
pip install -r requirements.txt
Copy .sample.env and configure the indicated values.
Run huggingface-cli login and paste a HF API Token.
Edit app/levels.yaml - and create your own levels. See example-levels.yaml.
Start the server with:
uvicorn app.main:app --host 127.0.0.1 --port 8000 --proxy-headersOnce running, open http://localhost:8000 in your browser.
