AI Feature
The boilerplate includes an AI feature module with a streaming OpenAI integration. Use it as a ready foundation for shipping your own AI workflow without designing the request, response, and browser streaming loop from scratch.
What the tools app contains
<project_slug>/<project_slug>/tools/
├── apis.py
├── gpt.py
├── static/js/tools.js
├── templates/tools/cover_letter.html
├── urls.py
└── views.py
The key files are:
views.py: serves the included cover letter pageapis.py: receives front-end requests and returns a streaming responsegpt.py: centralizes the OpenAI client callstatic/js/tools.js: holds the front-end JavaScript for the default AI flowtemplates/tools/cover_letter.html: the default UI and access control
Enable OpenAI locally
Set your API key in the .env file, then reload the environment:
export OPENAI_API_KEY=your_openai_api_key
source .env
For Heroku production:
heroku config:set OPENAI_API_KEY=your_api_key
How the default flow works
The default implementation is a cover letter generator:
- the page lives at
/tools/cover-letter/ - the front end posts user input to
/tools/api/generate/ - the API view builds a prompt
- the OpenAI client streams text back to the browser
- the UI renders the response progressively
That streaming flow is the reusable part. Replace the prompt, model choice, UI, and post-processing with whatever fits your own product.
Access control in the default implementation
The default template gates the feature behind request.user.is_paid. That gives you a clear starting point for tying AI access to billing.
If you want to test the page locally without paid access, update the condition in templates/tools/cover_letter.html:
{% if request.user.is_authenticated and request.user.is_paid %}
You can loosen or replace that guard however you want once you start building your real product rules.
What to customize first
Most teams should change these parts first:
- the page copy and UX in
cover_letter.html - the request payload shape in
tools.js - the prompt construction in
apis.py - the model call in
gpt.py - the route names in
urls.py
Treat the included tool as infrastructure you customize, not as a fixed product requirement.