Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/ai_actions/extend_ai_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ For example, you can create a handler that connects to a translation model and u
You can execute AI Actions by using the [ActionServiceInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionServiceInterface.html) service, as in the following example:

``` php
[[= include_file('code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php', 86, 105) =]]
[[= include_file('code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php', 86, 105, remove_indent=True) =]]
```

The `GenerateAltTextAction` is a built-in action that implements the [ActionInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionInterface.html), takes an [Image](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-Action-DataType-Image.html) as an input, and generates the alternative text in the response.
Expand Down Expand Up @@ -77,7 +77,7 @@ See [Action Configuration Search Criteria reference](action_configuration_criter
The following example creates a new Action Configuration:

``` php hl_lines="3 17"
[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 46, 63) =]]
[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 46, 63, remove_indent=True) =]]
```

Actions Configurations are tied to a specific Action Type and are translatable.
Expand All @@ -88,7 +88,7 @@ Reuse existing Action Configurations to simplify the execution of AI Actions.
You can pass one directly to the `ActionServiceInterface::execute()` method:

``` php hl_lines="7-8"
[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 64, 72) =]]
[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 64, 72, remove_indent=True) =]]
```

The passed Action Configuration is only taken into account if the Action Context was not passed to the Action directly using the [ActionInterface::setActionContext()](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionInterface.html#method_hasActionContext) method.
Expand Down
10 changes: 9 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""


def define_env(env):

Check failure on line 23 in main.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 83 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=ezsystems_developer-documentation&issues=AZzcf1KPH5pNXE3_guLg&open=AZzcf1KPH5pNXE3_guLg&pullRequest=3081
"""
This is the hook for defining variables, macros and filters

Expand All @@ -29,18 +29,26 @@
"""

@env.macro
def include_file(filename, start_line=0, end_line=None, glue=''):
def include_file(filename, start_line=0, end_line=None, glue='', remove_indent=False):
"""
Include a file,
optionally indicating start_line and end_line (start counting from 0)
optionally set a glue string to lead every string except the first one (can be used for indent)
optionally remove common leading whitespace from all lines (remove_indent=True)
The path is relative to the top directory of the documentation
project.
"""
full_filename = os.path.join(env.project_dir, filename)
with open(full_filename, 'r') as f:
lines = f.readlines()
line_range = lines[start_line:end_line]

if remove_indent:
non_empty = [l for l in line_range if l.strip()]
if non_empty:
indent = min(len(l) - len(l.lstrip()) for l in non_empty)
line_range = [l[indent:] if l.strip() else l for l in line_range]

return glue.join(line_range)

@env.macro
Expand Down
Loading