Skip to main content

Get a hand writing your content with AI super powers!

Project description

wagtail-ai

Wagtail AI

Get help with your content using AI superpowers.

License: MIT PyPI version ai CI

Wagtail AI integrates Wagtail with OpenAI's APIs (think ChatGPT) to help you write and correct your content.

Right now, it can:

  • Finish what you've started - write some text and tell Wagtail AI to finish it off for you
  • Correct your spelling/grammar
  • Let you add your own custom prompts

https://user-images.githubusercontent.com/27112/223072938-8cb5ccff-4835-489a-8be4-cca85001885e.mp4

Requirements & Costs

You'll need a paid OpenAI account and an API key. There'll also be some cost involved. For the API used here, OpenAI charges $0.002 for 1,000 tokens (a word is about 1.3 tokens). Every token sent to the API, and every token we get back counts, so you can expect using 'correction' on 1,000 word paragraph to cost roughly:

  • (1,000 * 1.3) + (35 * 1.3) (for the initial prompt) tokens sent to the API
  • + (1,000 * 1.3) tokens received from the API
  • = 2,645 tokens = $0.0053

The Future

Wagtail AI is very new. Here's some things we'd like to do:

  • Streaming support - the API supports server-sent events, we could do the same
  • A nice UI - it's a bit rough right now
  • Reduce bundle size
  • Internationalisation on text and support for different language prompts
  • Find a better way to hook in to Draftail to do things like show progress bars/spinners.
  • Add more AI behaviours and features - content recommendations, content based Q&A tools, better ways to direct the prompt.
  • Tests!

If you're interested in working on these things, please do!

Links

Supported Versions

  • Wagtail 4.0, 4.1 and 4.2

Installation

  • python -m pip install wagtail-ai
  • Add wagtail_ai to your INSTALLED_APPS
  • Add an OPENAI_API_KEY = "{api_key}" to your Django settings file, replacing {api_key} with your OpenAI API key.

Configuration

Adding Your Own Prompts

To add custom prompts, add the WAGTAIL_AI_PROMPTS setting to your settings file. This is a list of all the prompts to enable, where each prompt is a dictionary in the form:

{
    "label": "Short Label",
    "description": "More complete description",
    "prompt": "The prompt to be sent before your text to the OpenAI API",
    "method": "replace/append",
}

where method is either:

  • replace if the AI response should replace the text
  • append if the response should be appended to the end of the existing text

e.g. to extend the default prompts with your own, add:

import wagtail_ai

WAGTAIL_AI_PROMPTS = wagtail_ai.DEFAULT_PROMPTS + [
    {
        "label": "Simplify",
        "description": "Rewrite your text in a simpler form",
        "prompt": "Rewrite the following text to make it simper and more succinct",
        "method": "replace",
    }
]

Contributing

Install

To make changes to this project, first clone this repository:

git clone https://github.com/tomusher/wagtail-ai.git
cd wagtail-ai

With your preferred virtualenv activated, install testing dependencies:

Using pip

python -m pip install --upgrade pip>=21.3
python -m pip install -e .[testing] -U

Using flit

python -m pip install flit
flit install

pre-commit

Note that this project uses pre-commit. It is included in the project testing requirements. To set up locally:

# go to the project directory
$ cd wagtail-ai
# initialize pre-commit
$ pre-commit install

# Optional, run all checks once for this, then the checks will run only on the changed files
$ git ls-files --others --cached --exclude-standard | xargs pre-commit run --files

How to run tests

Now you can run tests as shown below:

tox

or, you can run them for a specific environment tox -e python3.8-django3.2-wagtail2.15 or specific test tox -e python3.9-django3.2-wagtail2.15-sqlite wagtail-ai.tests.test_file.TestClass.test_method

To run the test app interactively, use tox -e interactive, visit http://127.0.0.1:8020/admin/ and log in with admin/changeme.

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

wagtail_ai-1.1.1.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

wagtail_ai-1.1.1-py2.py3-none-any.whl (12.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file wagtail_ai-1.1.1.tar.gz.

File metadata

  • Download URL: wagtail_ai-1.1.1.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for wagtail_ai-1.1.1.tar.gz
Algorithm Hash digest
SHA256 bae9a130f31b7a4f35e5776ede6d8f302672477c49b2c79adc6680cb16cdf261
MD5 dd04cd694efcb0c535e6bf78ee1f6d3d
BLAKE2b-256 d2a20a24b06be9c5cc8eb056af5abaad7adc9d26f5a13d909fcb1166314962be

See more details on using hashes here.

File details

Details for the file wagtail_ai-1.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_ai-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fb7fd2b085caea3677fb7aaefbc33fcd6b9aa83fd8830292bcf9bf7fa262da9f
MD5 c2415d6d3bf626732500c086da28c100
BLAKE2b-256 c286c61b8344e8f4794865d4dfbcabb2fb88638ad79c3c1b00ecbe81232714f7

See more details on using hashes here.

Supported by

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