AI field enrichment — shared prefill orchestration for Django platform apps
Project description
iil-fieldprefill
AI field enrichment — shared prefill orchestration for Django platform apps.
ADR-107: Use iil-fieldprefill as shared AI field enrichment layer.
Installation
pip install iil-fieldprefill # Core only
pip install 'iil-fieldprefill[django]' # With Django HTMX mixin
pip install 'iil-fieldprefill[promptfw]' # With promptfw templates
pip install 'iil-fieldprefill[all]' # Everything
Quick Start
from fieldprefill import prefill_field, PrefillResult
result: PrefillResult = prefill_field(
field_key="geltungsbereich",
prompt="Beschreibe den Geltungsbereich...",
action_code="ex_doc_prefill",
max_tokens=2048,
)
print(result.content) # Generated text
print(result.tokens_used) # Input + output tokens
print(result.model) # e.g. "gpt-4o"
print(result.latency_ms) # Call duration
Multi-Field Prefill (v0.2.0+)
Enrich multiple fields in a single LLM call with structured JSON response:
from fieldprefill import prefill_fields
result = prefill_fields(
field_keys=["description", "emotional_arc"],
prompt="Enrich this chapter with a detailed description and emotional arc.",
action_code="outline_enrich",
context={"title": "Chapter 1", "act": "Act I", "beat_phase": "Inciting Incident"},
scope="writing.outline_enrichment",
)
# Access individual fields from JSON response
node.description = result.get("description")
node.emotional_arc = result.get("emotional_arc")
# Or get full dict
data = result.as_dict() # {"description": "...", "emotional_arc": "..."}
Cross-Hub Usage
risk-hub — Hazard field enrichment
# Register retrievers in AppConfig.ready()
from fieldprefill.retrievers import register_retriever
@register_retriever("sds")
def get_sds_texts(tenant_id, instance=None):
from substances.models import Substance
return [s.summary for s in Substance.objects.filter(tenant_id=tenant_id)]
# Prefill a field using existing document context
result = prefill_field(
field_key="schutzmassnahmen",
prompt="Beschreibe die erforderlichen Schutzmaßnahmen...",
action_code="ex_doc_prefill",
sources=["sds", "gefaehrdungsbeurteilung"],
scope="explosionsschutz.ex_doc",
tenant_id=request.tenant_id,
)
writing-hub — Outline node enrichment
@register_retriever("project_context")
def get_project_context(owner_id, instance=None):
from apps.authoring.services.project_context_service import ProjectContextService
ctx = ProjectContextService().get_context(str(instance.pk))
return [ctx.to_prompt_block()]
result = prefill_fields(
field_keys=["description", "emotional_arc"],
prompt="Verfeinere dieses Kapitel mit detaillierter Beschreibung und emotionalem Bogen.",
action_code="chapter_outline",
sources=["project_context"],
context={"title": node.title, "act": node.act, "beat_phase": node.beat_phase},
scope="writing.outline_enrichment",
tenant_id=user.pk,
instance=node.outline_version.project,
)
Django HTMX Mixin
from fieldprefill.django import PrefillViewMixin
class MyEditView(LoginRequiredMixin, PrefillViewMixin, UpdateView):
prefill_action_code = "ex_doc_prefill"
prefill_scope = "explosionsschutz.ex_doc"
Architecture
App registers retrievers fieldprefill orchestrates aifw calls LLM
───────────────────────── → ───────────────────────── → ──────────────
@register_retriever("sds") 1. get_context_texts() sync_completion()
@register_retriever("gbu") 2. build_messages() completion()
register_system_prompt(...) 3. call_llm_sync/async()
4. PrefillResult
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file iil_fieldprefill-0.2.0.tar.gz.
File metadata
- Download URL: iil_fieldprefill-0.2.0.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
188ba8cc9a0ec746dc77f8c2d8acbb61df4977bc86d91f2420f38012d3f3d7b3
|
|
| MD5 |
7a7a05dc94fd7a573657d4f5045dc763
|
|
| BLAKE2b-256 |
b06fd39c4182fdd3a3fc08fb7873d698fbce8a188a154cc5f73cfaace1eacd31
|
Provenance
The following attestation bundles were made for iil_fieldprefill-0.2.0.tar.gz:
Publisher:
publish.yml on achimdehnert/iil-fieldprefill
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
iil_fieldprefill-0.2.0.tar.gz -
Subject digest:
188ba8cc9a0ec746dc77f8c2d8acbb61df4977bc86d91f2420f38012d3f3d7b3 - Sigstore transparency entry: 1256661221
- Sigstore integration time:
-
Permalink:
achimdehnert/iil-fieldprefill@9520fc5aeecee2fe4666656633e979999b46e108 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/achimdehnert
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9520fc5aeecee2fe4666656633e979999b46e108 -
Trigger Event:
push
-
Statement type:
File details
Details for the file iil_fieldprefill-0.2.0-py3-none-any.whl.
File metadata
- Download URL: iil_fieldprefill-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
916a47b7e78a2e655abbb44c2ee4ae6e6c966ffefd68c189517c41c053ba86d3
|
|
| MD5 |
2c1840e6f73aafb14512c97cadff7243
|
|
| BLAKE2b-256 |
bc4edee04745af6e50cc5d8a9f718d130909e3b43b4362b618f31ce13436c100
|
Provenance
The following attestation bundles were made for iil_fieldprefill-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on achimdehnert/iil-fieldprefill
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
iil_fieldprefill-0.2.0-py3-none-any.whl -
Subject digest:
916a47b7e78a2e655abbb44c2ee4ae6e6c966ffefd68c189517c41c053ba86d3 - Sigstore transparency entry: 1256661292
- Sigstore integration time:
-
Permalink:
achimdehnert/iil-fieldprefill@9520fc5aeecee2fe4666656633e979999b46e108 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/achimdehnert
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9520fc5aeecee2fe4666656633e979999b46e108 -
Trigger Event:
push
-
Statement type: