Skip to content

Commit 735a210

Browse files
authored
feat: Add parameter enable_describe_image to ImageBone (#1)
By default it's set to default and appends the Bone Action DESCRIBE_IMAGE to its bone `params`.
1 parent 24627c5 commit 735a210

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/viur/assistant/bones/actions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525

2626
import typing as t
2727

28+
__all__ = [
29+
"BONE_ACTION_KEY",
30+
"BoneAction",
31+
]
32+
2833
BONE_ACTION_KEY: t.Final[str] = "actions"
2934
"""The key of the parameter"""
3035

src/viur/assistant/bones/image.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@
44
from viur.core.bones import FileBone, StringBone
55
from viur.core.skeleton import RelSkel
66

7+
from .actions import *
8+
9+
__all__ = [
10+
"ImageBone",
11+
"ImageBoneRelSkel",
12+
]
13+
714

815
class ImageBoneRelSkel(RelSkel):
16+
"""
17+
RelSkel designed to use as using skeleton in a ``ImageBone``.
18+
"""
19+
920
alt = StringBone(
1021
descr=i18n.translate("viur.assistant.imagebone.alt.descr", "Alternative text", public=True),
1122
searchable=True,
@@ -15,15 +26,43 @@ class ImageBoneRelSkel(RelSkel):
1526

1627

1728
class ImageBone(FileBone):
29+
"""
30+
A specialized ``FileBone`` for image files.
31+
32+
This bone type extends ``FileBone`` by:
33+
34+
- Restricting accepted MIME types to images (by default).
35+
- Has a using skel with an alt ``StringBone``.
36+
- Optionally enabling the *Describe Image* bone action, which allows AI to generate an alt-text or caption
37+
for the uploaded image via an admin-triggerable action.
38+
"""
39+
1840
type = FileBone.type + ".image"
1941

2042
def __init__(
2143
self,
2244
*,
2345
using: t.Type[RelSkel] = ImageBoneRelSkel,
2446
validMimeTypes: None | t.Iterable[str] = ("image/*",),
47+
enable_describe_image: bool = True,
2548
**kwargs,
2649
):
50+
"""
51+
Initialize an ImageBone, a file-based bone specialized for handling image uploads.
52+
53+
Optionally adds a bone action that allows AI-based image description (alt-text generation)
54+
to be triggered from within the admin interface.
55+
56+
:param using: The relational skeleton class used for additional data of this image.
57+
Defaults to ``ImageBoneRelSkel``, including the alt ``StringBone``.
58+
:param validMimeTypes: A list of accepted MIME types. Defaults to only allow image types (``("image/*",)``).
59+
:param enable_describe_image: If ``True``, the bone will include the ``DESCRIBE_IMAGE`` bone action,
60+
allowing AI-assisted image description via the vi-admin UI.
61+
:param kwargs: Additional keyword arguments passed to the base ``FileBone``.
62+
"""
63+
if enable_describe_image:
64+
params = kwargs.setdefault("params", {})
65+
params[BONE_ACTION_KEY] = [*params.get(BONE_ACTION_KEY, []), BoneAction.DESCRIBE_IMAGE]
2766
super().__init__(
2867
using=using,
2968
validMimeTypes=validMimeTypes,

0 commit comments

Comments
 (0)