Metadata-Version: 2.5
Name: django-wagtail-ai-generation
Version: 0.1.1
Summary: Wagtail admin AI assistant for StreamField bodies (copy/paste and optional in-app LLM)
Project-URL: Homepage, https://github.com/AymaneNahji/django-wagtail-ai-generation
Project-URL: Documentation, https://github.com/AymaneNahji/django-wagtail-ai-generation#readme
Project-URL: Repository, https://github.com/AymaneNahji/django-wagtail-ai-generation
Author-email: Aymane Nahji <aymanenahjidev@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: ai,cms,django,llm,streamfield,wagtail
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 5
Classifier: Framework :: Wagtail
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.11
Requires-Dist: django>=5.0
Requires-Dist: pillow>=10.0
Requires-Dist: wagtail>=6.0
Provides-Extra: dev
Requires-Dist: pytest-django>=4.11; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Description-Content-Type: text/markdown

# django-wagtail-ai-generation

**A floating AI assistant for the Wagtail page editor** — generate StreamField content with a live JSON schema, paste results from any LLM, or wire your own model for one-click **Generate & apply**.

Portable Django package · MIT · by [Aymane Nahji](mailto:aymanenahjidev@gmail.com)

[![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
[![Django 5+](https://img.shields.io/badge/django-5%2B-092e20.svg)](https://www.djangoproject.com/)
[![Wagtail 6+](https://img.shields.io/badge/wagtail-6%2B-007d7e.svg)](https://wagtail.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

---

## Why this package

Editors stay inside Wagtail. The assistant inspects **the page you are editing** and every **`StreamField`** on that model, then builds prompts that match **your** block types — `CharBlock`, `RichTextBlock`, localized structs, images, Lucide icons, and more.

| Mode | Setup | Best for |
|------|--------|----------|
| **Copy & paste** | `pip install` + `INSTALLED_APPS` | Teams using ChatGPT, Claude, or any external tool |
| **In-app agent** | `WAGTAIL_AI_GENERATION_LLM_ENABLED` + your hook callables | One-click generation inside the admin bubble |

No page model name, no hard-coded `body` field, no LLM API keys in settings unless you opt in.

---

## Quick start

```bash
pip install django-wagtail-ai-generation
```

```python
INSTALLED_APPS = [
    # ...
    "wagtail",
    "wagtail_ai_generation",
]
```

Expose your stream fields with a normal `FieldPanel`. If the user can edit the page and the model has at least one `StreamField`, the bubble appears automatically — **no extra panel required**.

For **tests or copy/paste-only** deployments:

```python
WAGTAIL_AI_GENERATION_LLM_ENABLED = False  # default
```

---

## What you get

- **Floating assistant** on page edit — schema-aware prompts and JSON apply in one place.
- **Per-block actions** — **AI edit** and **AI replace** on each stream block (alongside your other block actions).
- **Live schema bundle** — minimal shape examples derived from block types on the current page.
- **Image helpers** — optional download of placeholder image URLs into Wagtail `Image` records (requires Pillow).
- **Translations** — admin strings packaged for English, French, and Arabic.
- **Strict optional LLM wiring** — when the agent is enabled, missing hooks fail fast at startup with actionable `ImproperlyConfigured` messages.

Pair with **[django-wagtail-icon-chooser](https://github.com/AymaneNahji/django-wagtail-icon-chooser)** so `IconChooserBlock` values appear as `lucide_icon` in generated JSON.

---

## Optional in-app LLM

Enable only when you want a **Generate and apply** tab in the bubble:

```python
WAGTAIL_AI_GENERATION_LLM_ENABLED = True

WAGTAIL_AI_GENERATION_LLM_HOOKS = {
    "agent_context": "myapp.llm.agent_context",
    "get_connection": "myapp.llm.get_connection",
    "run_completion": "myapp.llm.run_completion",
    "connection_not_found_exception": "myapp.llm.NoConnection",
    "admin_url_names": {
        "list": "myapp:connection_list",
        "create": "myapp:connection_create",
        "api": "myapp:connection_api",
        "setCurrentModel": "myapp:connection_set_model",
    },
    # "connection_summary": "myapp.llm.connection_summary",  # optional
}
```

Every hook must be set explicitly — there is **no** automatic coupling to a companion app. Reference callables you can delegate to: `wagtail_ai_generation.llm_defaults.run_litellm_completion` and `.connection_summary`.

Hook contract, settings tables, and schema notes: **[wagtail_ai_generation/README.md](wagtail_ai_generation/README.md)**.

---

## Requirements

| Dependency | Version |
|------------|---------|
| Python | 3.11+ |
| Django | 5.0+ |
| Wagtail | 6.0+ |
| Pillow | 10.0+ (image URLs in AI JSON) |

---

## Admin API (staff + CSRF)

| Method | Path | When |
|--------|------|------|
| `GET` | `…/ai-generation/context/` | Page has StreamFields |
| `POST` | `…/ai-generation/` | Apply pasted JSON |
| `POST` | `…/ai-generation/run/` | `LLM_ENABLED` and valid hooks |

Paths are under your Wagtail admin URL prefix.

---

## Develop & test

```bash
pip install -e ".[dev]"
PYTHONPATH=. DJANGO_SETTINGS_MODULE=tests_project.settings python -m django test wagtail_ai_generation
```

The bundled test project keeps `WAGTAIL_AI_GENERATION_LLM_ENABLED = False` so the suite runs without a connections backend.

---

## Wagtail toolkit

Built to compose with the rest of the stack:

| Package | Role |
|---------|------|
| [django-wagtail-blocks-exchange](https://github.com/AymaneNahji/django-wagtail-blocks-exchange) | Copy blocks across pages and StreamFields |
| [django-wagtail-icon-chooser](https://github.com/AymaneNahji/django-wagtail-icon-chooser) | Lucide icon picker; AI schema type `lucide_icon` |

---

## License

MIT — see [LICENSE](LICENSE).