For more information, see the corresponding blog post.
This code will help you add buttons next to Django Admin text fields that will generate copy according to a specific prompt and data payload. For example, at my company (an ecommerce site) we have a section on our product detail pages titled "Why we believe in this product", backed by an attribute on the Product model called why_we_believe. In the Django Admin, when viewing a Product model, there is a button that our merchandising team can use to populate the field.
The underlying prompts are editable in the admin as well so users can tweak the copy that ChatGPT is generating without getting in touch with engineering:
And a playground area allows admin users to test the prompts out without leaving Django.
First, the usual:
- Install the app (adding
llm
toINSTALLED_APPS
in settings) - Add a valid
OPENAI_API_KEY
tosettings
- Include llm/urls.py in your Django project
- Run migrations
Then, create your own prompts, prompt data, urls, and register the widgets. The easiest way to do this is simply search for "TODO" in this repo. Examples are given in code for each step.