Skip to content

Commit 09b1b9a

Browse files
committed
docs: More documentation
1 parent 5d71675 commit 09b1b9a

File tree

7 files changed

+121
-7
lines changed

7 files changed

+121
-7
lines changed

docs/bone-action.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Bone Actions
2+
============
3+
4+
This package is primarily intended to integrate AI-powered functionality
5+
into the ViUR administrative interface (vi-admin).
6+
To support seamless interaction within the admin UI,
7+
it defines identifiers for so-called *Bone Actions* as expected by the admin.
8+
9+
Bone Actions are interactive tools and helpers that can be attached
10+
to specific bones within edit form views in vi-admin.
11+
By enabling AI-driven features—such as text translation or image description
12+
as Bone Actions, users can conveniently trigger complex tasks
13+
on individual bones without leaving the context of the admin interface.
14+
15+
16+
Translate Action:
17+
-----------------
18+
19+
Activates a translation tool for multilingual bones.
20+
21+
.. code-block:: python
22+
23+
descr = TextBone(
24+
languages=["de", "en"],
25+
params={
26+
BONE_ACTION_KEY: [BoneAction.TRANSLATE],
27+
},
28+
)
29+
30+
31+
32+
Image Describe Action:
33+
----------------------
34+
35+
Activates a description tool of alt-texts for images.
36+
37+
.. code-block:: python
38+
39+
image = ImageBone(
40+
params={
41+
BONE_ACTION_KEY: [BoneAction.DESCRIBE_IMAGE],
42+
},
43+
)
44+

docs/conf.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,12 @@
227227

228228
# Output file base name for HTML help builder.
229229
htmlhelp_basename = "viur-assistant-doc"
230+
231+
def skip_util_classes(app, what, name, obj, skip, options):
232+
print(f"{app=} {what=} {name=} {obj=} {skip=} {options=}")
233+
if what == "data" and name.endswith(".logger"):
234+
skip = True
235+
return skip
236+
237+
def setup(sphinx):
238+
sphinx.connect("autoapi-skip-member", skip_util_classes)

docs/index.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Welcome to ViUR Assistant
1616

1717

1818
.. TODO:
19-
.. image:: images/viur-assistant.svg
19+
.. image:: images/viur-assistant.svg
2020

2121
ViUR Assistant is a powerful Python module designed to integrate AI assistant
2222
capabilities seamlessly into your `ViUR <https://www.viur.dev>`_ projects.
@@ -41,7 +41,8 @@ Dependencies
4141

4242

4343
.. toctree::
44-
:maxdepth: 2
45-
:caption: ViUR Assistant
44+
:maxdepth: 3
45+
:caption: ViUR Assistant
4646

47-
getting-started
47+
getting-started
48+
bone-action

src/viur/assistant/bones/__init__.py

Whitespace-only changes.

src/viur/assistant/bones/actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
)
1818
19-
descr = ImageBone(
19+
image = ImageBone(
2020
params={
2121
BONE_ACTION_KEY: [BoneAction.DESCRIBE_IMAGE],
2222
},

src/viur/assistant/modules/__init__.py

Whitespace-only changes.

src/viur/assistant/modules/assistant.py

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import openai
1111
from openai.types import ChatModel
1212
from openai.types.chat import ChatCompletionMessageParam
13-
from viur.core import conf, current, errors, exposed, utils
13+
from viur.core import conf, current, db, errors, exposed, utils
1414
from viur.core.decorators import access
1515
from viur.core.prototypes import List, Singleton, Tree
1616

@@ -153,6 +153,21 @@ def generate_script(
153153
return message.model_dump_json() # TODO: parse real "code" value
154154

155155
def get_viur_structures(self, modules_to_include: t.Iterable[str]) -> dict[str, dict]:
156+
"""
157+
Collect and return ViUR module structures for a given list of module names.
158+
159+
For each named module, its structure is extracted if it is of type ``List`` or ``Tree``.
160+
``Tree`` structures will return separate entries for ``node`` and ``leaf`` skeletons.
161+
162+
:param modules_to_include: List of ViUR module names to retrieve structures for.
163+
:return: A dictionary mapping module names to their respective structure definitions.
164+
For ``Tree`` modules, nested keys ``"node"`` and ``"leaf"`` are returned.
165+
166+
:raises ValueError: If a module exists but is not a supported type (i.e., not ``List`` or ``Tree``).
167+
168+
.. note::
169+
Modules that are missing or not found are silently skipped.
170+
"""
156171
structures_from_viur = {}
157172
for module_name in modules_to_include:
158173
module = getattr(conf.main_app.vi, module_name, None)
@@ -185,6 +200,28 @@ def translate(
185200
simplified: bool = False,
186201
characteristic: t.Optional[str] = None,
187202
):
203+
"""
204+
Translate a given text into a target language, optionally using a specific style.
205+
206+
This method sends the input text to OpenAI with instructions to
207+
translate it into the requested language, optionally applying predefined translation
208+
characteristics such as simplification.
209+
210+
:param text: The source text to translate.
211+
:param language: The target language code (e.g. ``"de"``, ``"en"``, ``"de-x-simple"``).
212+
:param simplified: **Deprecated** – Use ``characteristic="simplified"`` instead.
213+
When ``True``, applies a simplified language style.
214+
:param characteristic: Optional translation style (e.g. ``"simplified"``, ``"formal"``, etc.)
215+
as defined in ``CONFIG.translate_language_characteristics``.
216+
:return: Translated text as a plain string. HTML tags from the original text are preserved.
217+
218+
:raises BadRequest: If both ``simplified`` and ``characteristic`` are used simultaneously.
219+
:raises InternalServerError: If configuration is missing.
220+
221+
.. note::
222+
- The translation style is determined by merging base rules (`*`) and the selected characteristic.
223+
- The returned translation contains only the translated text, with no explanation or additional formatting.
224+
"""
188225
if simplified:
189226
if characteristic is not None:
190227
raise errors.BadRequest("Cannot use parameter *simplified* and *characteristic* at the same time")
@@ -218,11 +255,34 @@ def translate(
218255
@access("user-view")
219256
def describe_image(
220257
self,
221-
filekey: str,
258+
filekey: db.Key | str,
222259
prompt: str = "",
223260
context: str = "",
224261
language: str | None = None,
225262
):
263+
"""
264+
Generate an HTML ``alt`` attribute description for a given image using OpenAi.
265+
266+
This method reads an image via its filekey, resizes it to a configured pixel target,
267+
and sends it along with optional prompt and context data to an OpenAI model.
268+
The model returns a plain-text alternative description for accessibility purposes,
269+
formatted as an HTML ``alt`` text in the specified language.
270+
271+
:param filekey: Key identifying the image file in the ViUR file module.
272+
(Key of the :class:`file skeleton <viur.core.modules.file.FileLeafSkel>`).
273+
:param prompt: Optional user-defined hint or instruction for how the image should be interpreted.
274+
:param context: Optional additional background information to support a better description.
275+
:param language: Target language code for the generated description (e.g., ``"en"``, ``"de-x-simple"``).
276+
Falls back to the current session language if not specified.
277+
:return: A plain-text string suitable for use in an HTML ``alt`` attribute (no quotes or labels).
278+
279+
:raises InternalServerError: If required configuration is missing.
280+
:raises NotFound: If the referenced image file could not be loaded.
281+
282+
.. note::
283+
- The image is resized and converted to JPEG before being sent to the model.
284+
- This function uses a preconfigured OpenAI model, pixel count, and JPEG quality settings.
285+
"""
226286
if not (skel := self.getContents()):
227287
raise errors.InternalServerError(descr="Configuration missing")
228288

0 commit comments

Comments
 (0)