Skip to content

Commit f14c04e

Browse files
committed
Added extending AI documentation
1 parent e9b50b8 commit f14c04e

File tree

56 files changed

+3047
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3047
-15
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { addModule } from '../../vendor/ibexa/connector-ai/src/bundle/Resources/public/js/core/create.ai.module';
2+
import TranscribeAudio from './transcribe.audio';
3+
4+
addModule(TranscribeAudio);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import BaseAIComponent from '../../vendor/ibexa/connector-ai/src/bundle/Resources/public/js/core/base.ai.component';
2+
3+
export default class TranscribeAudio extends BaseAIComponent {
4+
constructor(mainElement, config) {
5+
super(mainElement, config);
6+
7+
this.requestHeaders = {
8+
Accept: 'application/vnd.ibexa.api.ai.AudioText+json',
9+
'Content-Type': 'application/vnd.ibexa.api.ai.TranscribeAudio+json',
10+
};
11+
}
12+
13+
getAudioInBase64() {
14+
const request = new XMLHttpRequest();
15+
request.open('GET', this.inputElement.href, false);
16+
request.overrideMimeType('text/plain; charset=x-user-defined');
17+
request.send();
18+
19+
if (request.status === 200) {
20+
return this.convertToBase64(request.responseText);
21+
}
22+
else {
23+
this.processError('Error occured when decoding the file.');
24+
}
25+
}
26+
27+
getRequestBody() {
28+
const body = {
29+
TranscribeAudio: {
30+
Audio: {
31+
base64: this.getAudioInBase64(),
32+
},
33+
RuntimeContext: {},
34+
},
35+
};
36+
37+
if (this.languageCode) {
38+
body.TranscribeAudio.RuntimeContext.languageCode = this.languageCode;
39+
}
40+
41+
return JSON.stringify(body);
42+
}
43+
44+
afterFetchData(response) {
45+
super.afterFetchData();
46+
47+
if (response) {
48+
this.outputElement.value = response.AudioText.Text.text[0];
49+
}
50+
}
51+
52+
toggle(forceEnabled) {
53+
super.toggle(forceEnabled);
54+
55+
this.outputElement.disabled = !forceEnabled || !this.outputElement.disabled;
56+
}
57+
58+
convertToBase64(data) {
59+
let binary = '';
60+
61+
for (let i = 0; i < data.length; i++) {
62+
binary += String.fromCharCode(data.charCodeAt(i) & 0xff);
63+
}
64+
65+
return btoa(binary);
66+
}
67+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
parameters:
2+
# Admin siteaccess group name
3+
admin_group_name: admin_group
4+
5+
ibexa:
6+
siteaccess:
7+
list: [admin]
8+
groups:
9+
# WARNING: Do not remove or rename this group.
10+
# It's used to distinguish common siteaccesses from admin ones.
11+
# In case of multisite with multiple admin panels, remember to add any additional admin siteaccess to this group.
12+
admin_group: [admin]
13+
14+
system:
15+
admin_group:
16+
# System languages. Note that by default, content, content types, and other data are in eng-GB locale,
17+
# so removing eng-GB from this list may lead to errors or content not being shown, unless you change
18+
# all eng-GB data to other locales first.
19+
# For admin this needs to contain all languages you want to translate content to on the given repository.
20+
languages: [eng-GB]
21+
content_tree_module:
22+
contextual_tree_root_location_ids:
23+
- 2 # Home (Content structure)
24+
- 5 # Users
25+
- 43 # Media
26+
- 48 # Setup
27+
- 55 # Forms
28+
- 56 # Site skeletons
29+
- 60 # Components
30+
- 67 # Dashboards
31+
subtree_paths:
32+
content: /1/2/
33+
media: /1/43/
34+
page_builder:
35+
siteaccess_list: [ site ]
36+
assets:
37+
icon_sets:
38+
streamlineicons: /bundles/ibexaicons/img/all-icons.svg
39+
default_icon_set: streamlineicons
40+
content_type:
41+
about:
42+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#about'
43+
article:
44+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#article'
45+
blog:
46+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#blog'
47+
blog_post:
48+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#blog_post'
49+
editor:
50+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#author'
51+
folder:
52+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#folder'
53+
form:
54+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#form'
55+
place:
56+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#place'
57+
product:
58+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#product'
59+
field:
60+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#field'
61+
user:
62+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#user'
63+
user_group:
64+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#user_group'
65+
file:
66+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#file'
67+
gallery:
68+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#gallery'
69+
image:
70+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#image'
71+
video:
72+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#video'
73+
landing_page:
74+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#landing_page'
75+
default-config:
76+
thumbnail: '/bundles/ibexaicons/img/all-icons.svg#file'
77+
user_content_type_identifier: ['user', 'customer', 'member', 'editor']
78+
user_profile:
79+
enabled: true
80+
content_types: ['editor']
81+
field_groups: ['about', 'contact']
82+
default_page: 'dashboard'
83+
content:
84+
default_ttl: 0
85+
admin_ui_forms:
86+
content_edit:
87+
form_templates:
88+
- { template: '@ibexadesign/admin/ui/fieldtype/edit/form_fields_binary_ai.html.twig', priority: -10 } }
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# This file is the entry point to configure your own services.
2+
# Files in the packages/ subdirectory configure your dependencies.
3+
4+
# Put parameters here that don't need to change on each machine where the app is deployed
5+
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
6+
parameters:
7+
8+
services:
9+
# default configuration for services in *this* file
10+
_defaults:
11+
autowire: true # Automatically injects dependencies in your services.
12+
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
13+
14+
# makes classes in src/ available to be used as services
15+
# this creates a service per class whose id is the fully-qualified class name
16+
App\:
17+
resource: '../src/'
18+
exclude:
19+
- '../src/DependencyInjection/'
20+
- '../src/Entity/'
21+
- '../src/Kernel.php'
22+
23+
# add more service definitions when explicit configuration is needed
24+
# please note that last definitions always *replace* previous ones
25+
26+
App\Command\AddMissingAltTextCommand:
27+
arguments:
28+
$projectDir: '%kernel.project_dir%'
29+
30+
App\AI\Handler\LLaVATextToTextActionHandler:
31+
tags:
32+
- { name: ibexa.ai.action.handler, priority: 0 }
33+
- { name: ibexa.ai.action.handler.text_to_text, priority: 0 }
34+
35+
app.connector_ai.action_configuration.handler.llava_text_to_text.form_mapper.options:
36+
class: Ibexa\Bundle\ConnectorAi\Form\FormMapper\ActionConfiguration\ActionHandlerOptionsFormMapper
37+
arguments:
38+
$formType: 'App\Form\Type\TextToTextOptionsType'
39+
tags:
40+
- name: ibexa.connector_ai.action_configuration.form_mapper.options
41+
type: !php/const \App\AI\Handler\LLaVaTextToTextActionHandler::IDENTIFIER
42+
43+
App\AI\ActionType\TranscribeAudioActionType:
44+
arguments:
45+
$actionHandlers: !tagged_iterator
46+
tag: app.connector_ai.action.handler.audio_to_text
47+
default_index_method: getIdentifier
48+
index_by: key
49+
tags:
50+
- { name: ibexa.ai.action.type, identifier: !php/const \App\AI\ActionType\TranscribeAudioActionType::IDENTIFIER }
51+
52+
app.connector_ai.action_configuration.handler.transcribe_audio.form_mapper.options:
53+
class: Ibexa\Bundle\ConnectorAi\Form\FormMapper\ActionConfiguration\ActionTypeOptionsFormMapper
54+
arguments:
55+
$formType: 'App\Form\Type\TranscribeAudioOptionsType'
56+
tags:
57+
- name: ibexa.connector_ai.action_configuration.form_mapper.action_type_options
58+
type: !php/const \App\AI\ActionType\TranscribeAudioActionType::IDENTIFIER
59+
60+
App\AI\Handler\WhisperAudioToTextActionHandler:
61+
tags:
62+
- { name: ibexa.ai.action.handler, priority: 0 }
63+
- { name: app.connector_ai.action.handler.audio_to_text, priority: 0 }
64+
65+
Ibexa\Contracts\ConnectorAi\ActionConfiguration\OptionsFormatterInterface:
66+
alias: Ibexa\ConnectorAi\ActionConfiguration\JsonOptionsFormatter
67+
68+
#REST services
69+
App\AI\REST\Input\Parser\TranscribeAudio:
70+
parent: Ibexa\Rest\Server\Common\Parser
71+
tags:
72+
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.ai.TranscribeAudio }
73+
74+
App\AI\REST\Output\Resolver\AudioTextResolver:
75+
tags:
76+
- { name: ibexa.ai.action.mime_type, key: application/vnd.ibexa.api.ai.AudioText }
77+
78+
App\AI\REST\Output\ValueObjectVisitor\AudioText:
79+
parent: Ibexa\Contracts\Rest\Output\ValueObjectVisitor
80+
tags:
81+
- { name: ibexa.rest.output.value_object.visitor, type: App\AI\REST\Value\AudioText }
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\AI\Action;
6+
7+
use App\AI\DataType\Audio;
8+
use Ibexa\Contracts\ConnectorAi\Action\Action;
9+
10+
final class TranscribeAudioAction extends Action
11+
{
12+
private Audio $audio;
13+
14+
public function __construct(Audio $audio)
15+
{
16+
$this->audio = $audio;
17+
}
18+
19+
public function getParameters(): array
20+
{
21+
return [];
22+
}
23+
24+
public function getInput(): Audio
25+
{
26+
return $this->audio;
27+
}
28+
29+
public function getActionTypeIdentifier(): string
30+
{
31+
return 'transcribe_audio';
32+
}
33+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\AI\ActionType;
6+
7+
use App\AI\Action\TranscribeAudioAction;
8+
use App\AI\DataType\Audio;
9+
use Ibexa\Contracts\ConnectorAi\Action\DataType\Text;
10+
use Ibexa\Contracts\ConnectorAi\ActionInterface;
11+
use Ibexa\Contracts\ConnectorAi\ActionType\ActionTypeInterface;
12+
use Ibexa\Contracts\ConnectorAi\DataType;
13+
use Ibexa\Contracts\Core\Exception\InvalidArgumentException;
14+
15+
final class TranscribeAudioActionType implements ActionTypeInterface
16+
{
17+
public const IDENTIFIER = 'transcribe_audio';
18+
19+
/** @var iterable<\Ibexa\Contracts\ConnectorAi\Action\ActionHandlerInterface> */
20+
private iterable $actionHandlers;
21+
22+
/** @param iterable<\Ibexa\Contracts\ConnectorAi\Action\ActionHandlerInterface> $actionHandlers*/
23+
public function __construct(iterable $actionHandlers)
24+
{
25+
$this->actionHandlers = $actionHandlers;
26+
}
27+
28+
public function getIdentifier(): string
29+
{
30+
return self::IDENTIFIER;
31+
}
32+
33+
public function getName(): string
34+
{
35+
return 'Transcribe audio';
36+
}
37+
38+
public function getInputIdentifier(): string
39+
{
40+
return Audio::getIdentifier();
41+
}
42+
43+
public function getOutputIdentifier(): string
44+
{
45+
return Text::getIdentifier();
46+
}
47+
48+
public function getOptions(): array
49+
{
50+
return [];
51+
}
52+
53+
public function createAction(DataType $input, array $parameters = []): ActionInterface
54+
{
55+
if (!$input instanceof Audio) {
56+
throw new InvalidArgumentException(
57+
'audio',
58+
'expected \App\AI\DataType\Audio type, ' . get_debug_type($input) . ' given.'
59+
);
60+
}
61+
62+
return new TranscribeAudioAction($input);
63+
}
64+
65+
public function getActionHandlers(): iterable
66+
{
67+
return $this->actionHandlers;
68+
}
69+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\AI\DataType;
6+
7+
use Ibexa\Contracts\ConnectorAi\DataType;
8+
9+
/**
10+
* @implements DataType<string>
11+
*/
12+
final class Audio implements DataType
13+
{
14+
/** @var non-empty-array<string> */
15+
private array $base64;
16+
17+
/**
18+
* @param non-empty-array<string> $base64
19+
*/
20+
public function __construct(array $base64)
21+
{
22+
$this->base64 = $base64;
23+
}
24+
25+
public function getBase64(): string
26+
{
27+
return reset($this->base64);
28+
}
29+
30+
public function getList(): array
31+
{
32+
return $this->base64;
33+
}
34+
35+
public static function getIdentifier(): string
36+
{
37+
return 'audio';
38+
}
39+
}

0 commit comments

Comments
 (0)