Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mnocon committed Dec 12, 2024
1 parent e7a16ec commit 3f64772
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace App\AI\Action;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace App\AI\ActionType;

Expand Down
4 changes: 3 additions & 1 deletion code_samples/ai_actions/src/AI/DataType/Audio.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace App\AI\DataType;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace App\AI\Handler;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace App\AI\Handler;

Expand Down Expand Up @@ -47,7 +49,10 @@ public function handle(ActionInterface $action, array $context = []): ActionResp

$output = $process->getOutput();

$includeTimestamps = $action->getActionContext()?->getActionTypeOptions()->get('include_timestamps', false) ?? false;
$includeTimestamps = $action->getActionContext()
?->getActionTypeOptions()
->get('include_timestamps', false)
?? false;

if (!$includeTimestamps) {
$output = $this->removeTimestamps($output);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1);
declare(strict_types=1);

namespace App\AI\REST\Input\Parser;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1);
declare(strict_types=1);

namespace App\AI\REST\Output\Resolver;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1);
declare(strict_types=1);

namespace App\AI\REST\Output\ValueObjectVisitor;

Expand Down
2 changes: 1 addition & 1 deletion code_samples/ai_actions/src/AI/REST/Value/AudioText.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1);
declare(strict_types=1);

namespace App\AI\REST\Value;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1);
declare(strict_types=1);

namespace App\AI\REST\Value;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1);
declare(strict_types=1);

namespace App\Command;

Expand Down
12 changes: 6 additions & 6 deletions code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

declare(strict_types=1);
declare(strict_types=1);

namespace App\Command;

use Ibexa\AdminUi\Event\Options;
use Ibexa\Contracts\ConnectorAi\Action\ActionContext;
use Ibexa\Contracts\ConnectorAi\Action\DataType\Image;
use Ibexa\Contracts\ConnectorAi\Action\DataType\Text;
use Ibexa\Contracts\ConnectorAi\Action\GenerateAltTextAction;
use Ibexa\Contracts\ConnectorAi\Action\RuntimeContext;
use Ibexa\Contracts\ConnectorAi\ActionConfiguration\ActionConfigurationOptions;
use Ibexa\Contracts\ConnectorAi\ActionServiceInterface;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\FieldTypeService;
Expand Down Expand Up @@ -73,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$modifiedImages = $this->getModifiedImages();
$output->writeln(sprintf('Found %d modified image in the last 24h', $modifiedImages->getTotalCount()));

/** @var \Ibexa\Core\Repository\Values\Content\Content $content */
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content $content */
foreach ($modifiedImages as $content) {
/** @var ?Value $value */
$value = $content->getFieldValue(self::IMAGE_FIELD_IDENTIFIER);
Expand Down Expand Up @@ -104,9 +104,9 @@ private function getSuggestedAltText(string $imageEncodedInBase64, string $langu
$action->setRuntimeContext(new RuntimeContext(['languageCode' => $languageCode]));
$action->setActionContext(
new ActionContext(
new Options(['default_locale_fallback' => 'en']), // System context
new Options(['max_lenght' => 100]), // Action Type options
new Options( // Action Handler options
new ActionConfigurationOptions(['default_locale_fallback' => 'en']), // System context
new ActionConfigurationOptions(['max_lenght' => 100]), // Action Type options
new ActionConfigurationOptions( // Action Handler options
[
'prompt' => 'Generate the alt text for this image in less than 100 characters.',
'temperature' => 0.7,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1);
declare(strict_types=1);

namespace App\Form\Type;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1);
declare(strict_types=1);

namespace App\Form\Type;

Expand Down
2 changes: 1 addition & 1 deletion code_samples/ai_actions/src/Query/Search.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1);
declare(strict_types=1);

use Ibexa\Contracts\ConnectorAi\ActionConfiguration\ActionConfigurationQuery;
use Ibexa\Contracts\ConnectorAi\ActionConfiguration\Query\Criterion;
Expand Down
22 changes: 11 additions & 11 deletions docs/ai_actions/extend_ai_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ For example, you could write a handler that connects to a translation model and
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:

Check failure on line 13 in docs/ai_actions/extend_ai_actions.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/ai_actions/extend_ai_actions.md#L13

[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'
Raw output
{"message": "[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'", "location": {"path": "docs/ai_actions/extend_ai_actions.md", "range": {"start": {"line": 13, "column": 107}}}, "severity": "ERROR"}

``` php
[[= include_file('code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php', 99, 118) =]]
[[= include_file('code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php', 101, 120) =]]
```

The `GenerateAltTextAction` is a built-in action implementing the [ActionInterface](../api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionInterface.html), taking an [Image](../api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-Action-DataType-Image.html) as an input.
The `GenerateAltTextAction` is a built-in action implementing the [ActionInterface](../api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionInterface.html), taking an [Image](../api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-Action-DataType-Image.html) as an input and generating the alternative text in the response.

Check failure on line 19 in docs/ai_actions/extend_ai_actions.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/ai_actions/extend_ai_actions.md#L19

[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'
Raw output
{"message": "[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'", "location": {"path": "docs/ai_actions/extend_ai_actions.md", "range": {"start": {"line": 19, "column": 126}}}, "severity": "ERROR"}

This action is parameterized using the [RuntimeContext](../api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-Action-RuntimeContext.html) and the [ActionContext](../api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-Action-ActionContext.html), allowing you to pass additional options to the Action before it's executed.

Check failure on line 21 in docs/ai_actions/extend_ai_actions.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/ai_actions/extend_ai_actions.md#L21

[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'
Raw output
{"message": "[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'", "location": {"path": "docs/ai_actions/extend_ai_actions.md", "range": {"start": {"line": 21, "column": 98}}}, "severity": "ERROR"}

Expand All @@ -41,7 +41,7 @@ You can influence the execution of an Action with two events:

Below you can find the full example of a Symfony Command, together with a matching service definition. The command finds the images modified in the last 24 hours, and adds the alternative text to them if it's missing.

``` php hl_lines="85 98-123"
``` php hl_lines="87 100-125"
[[= include_file('code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php') =]]
```

Expand Down Expand Up @@ -72,7 +72,7 @@ You can get a specific Action Configuration using the `ActionConfigurationServic
The following example creates a new Action Configuration:

``` php hl_lines="3 17"
[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 57, 74) =]]
[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 59, 76) =]]
```

Actions Configurations are tied to a specific Action Type and are translatable.
Expand All @@ -82,7 +82,7 @@ Actions Configurations are tied to a specific Action Type and are translatable.
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', 75, 83) =]]
[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 77, 85) =]]
```

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.

Check failure on line 88 in docs/ai_actions/extend_ai_actions.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/ai_actions/extend_ai_actions.md#L88

[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'
Raw output
{"message": "[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'", "location": {"path": "docs/ai_actions/extend_ai_actions.md", "range": {"start": {"line": 88, "column": 209}}}, "severity": "ERROR"}
Expand All @@ -108,7 +108,7 @@ Create a class implementing the [ActionHandlerInterface](../api/php_api/php_api_

See the code sample below, together with a matching service definition:

``` php hl_lines="19 27-30 32-67 69-72"
``` php hl_lines="21 29-31 34-69 71-74"
[[= include_file('code_samples/ai_actions/src/AI/Handler/LLaVaTextToTextActionHandler.php') =]]
```

Expand All @@ -128,7 +128,7 @@ The built-in Action Types use service tags to find Action Handlers capable of ha
Form configuration makes the Handler configurable by using the back office.
The example handler uses the `system_prompt` option, which becomes part of the Action Configuration UI thanks to the following code:

``` php hl_lines="14-18"
``` php hl_lines="16-20"
[[= include_file('code_samples/ai_actions/src/Form/Type/TextToTextOptionsType.php') =]]
```

Expand Down Expand Up @@ -160,7 +160,7 @@ Start by creating your own Action Type, a class implementing the [ActionTypeInte
- identifier
- input type identifier
- output type identifier
- the Action object
- Action object

``` php
[[= include_file('code_samples/ai_actions/src/AI/ActionType/TranscribeAudioActionType.php') =]]
Expand Down Expand Up @@ -194,9 +194,9 @@ The `TranscribeAudio` Action Type requires adding two data classes that exists i

### Create custom Action Type options form

Custom Form Type is needed if the Action Type requires additional options configurable in the UI. The following example adds a simple checkbox field that will indicate to the Action Handler whether the transcription should include the timestamps.
Custom Form Type is needed if the Action Type requires additional options configurable in the UI. The following example adds a checkbox field that indicates to the Action Handler whether the transcription should include the timestamps.

``` php hl_lines="14-18"
``` php hl_lines="16-20"
[[= include_file('code_samples/ai_actions/src/Form/Type/TranscribeAudioOptionsType.php') =]]
```

Expand All @@ -210,7 +210,7 @@ The built-in `Ibexa\Bundle\ConnectorAi\Form\FormMapper\ActionConfiguration\Actio

An example Action Handler combines the input data and the Action Type options and passes them to the Whisper executable to form an Action Response. The language of the transcribed data is extracted from the Runtime Context for better results. The Action Type options provided in the Action Context dictate whether the timestamps will be removed before returning the result.

Check warning on line 211 in docs/ai_actions/extend_ai_actions.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/ai_actions/extend_ai_actions.md#L211

[Ibexa.FutureTense] Use present tense instead of future.
Raw output
{"message": "[Ibexa.FutureTense] Use present tense instead of future.", "location": {"path": "docs/ai_actions/extend_ai_actions.md", "range": {"start": {"line": 211, "column": 330}}}, "severity": "WARNING"}

``` php hl_lines="32-35 50"
``` php hl_lines="34-37 52-55"
[[= include_file('code_samples/ai_actions/src/AI/Handler/WhisperAudioToTextActionHandler.php') =]]
```

Expand Down
Binary file modified docs/ai_actions/img/transcribe_audio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/content_management/data_migration/importing_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,13 @@ When updating a content type, use:
[[= include_file('code_samples/data_migration/examples/ai/action_configuration_create.yaml') =]]
```

- Use the `update` mode to modify an existing one:
- Use the `update` mode to modify an existing action configuration:

``` yaml
[[= include_file('code_samples/data_migration/examples/ai/action_configuration_update.yaml') =]]
```

- Use the `delete` mode to delete an existing action configuration
- Use the `delete` mode to delete an existing action configuration:

``` yaml
[[= include_file('code_samples/data_migration/examples/ai/action_configuration_delete.yaml') =]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ month_change: true

# AI Actions Twig functions

AI Actions functions allows you to embed AI Actions in your templates.
AI Actions functions allows you to pass information about AI Actions to the Twig templates.

### `ibexa_ai_config()`

The `ibexa_ai_config` function loads an Action Type with the given identifier, which you can later use in templates to invoke an AI Action.
The `ibexa_ai_config` function loads the configuration of an Action Type with given identifier.

``` html+twig
{% set ai_config = ibexa_ai_config('refine_text') %}
Expand Down

0 comments on commit 3f64772

Please sign in to comment.