From 890c80eb124cd7676d8442aa51f28ff139705f49 Mon Sep 17 00:00:00 2001 From: bach Date: Mon, 16 Nov 2026 19:35:09 +0100 Subject: [PATCH] materio_ai: module skeleton, settings and schema (V1) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01ShDspHaZGwHoRZCsPBJzsM --- config/sync/core.extension.yml | 1 + config/sync/materio_ai.settings.yml | 8 ++ .../config/install/materio_ai.settings.yml | 12 +++ .../config/schema/materio_ai.schema.yml | 22 ++++++ .../custom/materio_ai/materio_ai.info.yml | 6 ++ .../materio_ai/materio_ai.links.menu.yml | 5 ++ .../materio_ai/materio_ai.permissions.yml | 4 + .../custom/materio_ai/materio_ai.routing.yml | 7 ++ .../custom/materio_ai/materio_ai.services.yml | 4 + .../materio_ai/src/Form/SettingsForm.php | 77 +++++++++++++++++++ 10 files changed, 146 insertions(+) create mode 100644 config/sync/materio_ai.settings.yml create mode 100644 web/modules/custom/materio_ai/config/install/materio_ai.settings.yml create mode 100644 web/modules/custom/materio_ai/config/schema/materio_ai.schema.yml create mode 100644 web/modules/custom/materio_ai/materio_ai.info.yml create mode 100644 web/modules/custom/materio_ai/materio_ai.links.menu.yml create mode 100644 web/modules/custom/materio_ai/materio_ai.permissions.yml create mode 100644 web/modules/custom/materio_ai/materio_ai.routing.yml create mode 100644 web/modules/custom/materio_ai/materio_ai.services.yml create mode 100644 web/modules/custom/materio_ai/src/Form/SettingsForm.php diff --git a/config/sync/core.extension.yml b/config/sync/core.extension.yml index 2a8ab60a..564b874f 100644 --- a/config/sync/core.extension.yml +++ b/config/sync/core.extension.yml @@ -122,6 +122,7 @@ module: maillog: 0 masquerade: 0 materio_admin: 0 + materio_ai: 0 materio_commerce: 0 materio_decoupled: 0 materio_expo: 0 diff --git a/config/sync/materio_ai.settings.yml b/config/sync/materio_ai.settings.yml new file mode 100644 index 00000000..03e79a42 --- /dev/null +++ b/config/sync/materio_ai.settings.yml @@ -0,0 +1,8 @@ +_core: + default_config_hash: __uY4VMv6UzzHCHq1eTjbhXofXp1BTtuR5VjcV_MHYM +enabled: false +url: 'http://ollama:11434' +model: 'bge-m3:567m' +dimension: 1024 +timeout: 10 +num_thread: 4 diff --git a/web/modules/custom/materio_ai/config/install/materio_ai.settings.yml b/web/modules/custom/materio_ai/config/install/materio_ai.settings.yml new file mode 100644 index 00000000..b4dd5e0d --- /dev/null +++ b/web/modules/custom/materio_ai/config/install/materio_ai.settings.yml @@ -0,0 +1,12 @@ +# Désactivé à l'installation : le module ne fait rien tant que « enabled » est faux. +enabled: false +# Service Ollama. En local : conteneur « ollama » du docker-compose. +# Sur le serveur : à surcharger dans settings.php (CT-materio_embed sur le pont privé). +url: 'http://ollama:11434' +model: 'bge-m3:567m' +dimension: 1024 +# Délai maximal d'un appel au modèle, en secondes. +timeout: 10 +# Threads de calcul envoyés à chaque appel (options.num_thread) : Ollama ne voit pas +# la limite de CPU du conteneur, sans ce réglage il lance trop de threads (mesure M2). +num_thread: 4 diff --git a/web/modules/custom/materio_ai/config/schema/materio_ai.schema.yml b/web/modules/custom/materio_ai/config/schema/materio_ai.schema.yml new file mode 100644 index 00000000..29735f07 --- /dev/null +++ b/web/modules/custom/materio_ai/config/schema/materio_ai.schema.yml @@ -0,0 +1,22 @@ +materio_ai.settings: + type: config_object + label: 'materiO AI settings' + mapping: + enabled: + type: boolean + label: 'Enabled' + url: + type: uri + label: 'Embedding service URL' + model: + type: string + label: 'Model' + dimension: + type: integer + label: 'Vector dimension' + timeout: + type: integer + label: 'Timeout (seconds)' + num_thread: + type: integer + label: 'Threads per call' diff --git a/web/modules/custom/materio_ai/materio_ai.info.yml b/web/modules/custom/materio_ai/materio_ai.info.yml new file mode 100644 index 00000000..7324ac35 --- /dev/null +++ b/web/modules/custom/materio_ai/materio_ai.info.yml @@ -0,0 +1,6 @@ +name: 'materiO AI' +type: module +description: 'Recherche par le sens : vectorisation des fiches avec un modèle d''embedding (bge-m3).' +core_version_requirement: ^10.3 || ^11 +package: 'Materio' +configure: materio_ai.settings diff --git a/web/modules/custom/materio_ai/materio_ai.links.menu.yml b/web/modules/custom/materio_ai/materio_ai.links.menu.yml new file mode 100644 index 00000000..2671f6a8 --- /dev/null +++ b/web/modules/custom/materio_ai/materio_ai.links.menu.yml @@ -0,0 +1,5 @@ +materio_ai.settings: + title: 'materiO AI' + description: 'Embedding service for the semantic search.' + route_name: materio_ai.settings + parent: system.admin_config_search diff --git a/web/modules/custom/materio_ai/materio_ai.permissions.yml b/web/modules/custom/materio_ai/materio_ai.permissions.yml new file mode 100644 index 00000000..33285199 --- /dev/null +++ b/web/modules/custom/materio_ai/materio_ai.permissions.yml @@ -0,0 +1,4 @@ +administer materio ai: + title: 'Administer materiO AI' + description: 'Configure the embedding service used by the semantic search.' + restrict access: true diff --git a/web/modules/custom/materio_ai/materio_ai.routing.yml b/web/modules/custom/materio_ai/materio_ai.routing.yml new file mode 100644 index 00000000..c9eab649 --- /dev/null +++ b/web/modules/custom/materio_ai/materio_ai.routing.yml @@ -0,0 +1,7 @@ +materio_ai.settings: + path: '/admin/config/search/materio-ai' + defaults: + _form: '\Drupal\materio_ai\Form\SettingsForm' + _title: 'materiO AI' + requirements: + _permission: 'administer materio ai' diff --git a/web/modules/custom/materio_ai/materio_ai.services.yml b/web/modules/custom/materio_ai/materio_ai.services.yml new file mode 100644 index 00000000..ec2a571e --- /dev/null +++ b/web/modules/custom/materio_ai/materio_ai.services.yml @@ -0,0 +1,4 @@ +services: + logger.channel.materio_ai: + parent: logger.channel_base + arguments: ['materio_ai'] diff --git a/web/modules/custom/materio_ai/src/Form/SettingsForm.php b/web/modules/custom/materio_ai/src/Form/SettingsForm.php new file mode 100644 index 00000000..2f56f5b0 --- /dev/null +++ b/web/modules/custom/materio_ai/src/Form/SettingsForm.php @@ -0,0 +1,77 @@ + 'checkbox', + '#title' => $this->t('Enabled'), + '#description' => $this->t('When disabled, no text is sent to the model and nothing is vectorized.'), + '#config_target' => 'materio_ai.settings:enabled', + ]; + $form['url'] = [ + '#type' => 'url', + '#title' => $this->t('Embedding service URL'), + '#description' => $this->t('Ollama base URL, for example http://ollama:11434. Usually overridden in settings.php per environment.'), + '#required' => TRUE, + '#config_target' => 'materio_ai.settings:url', + ]; + $form['model'] = [ + '#type' => 'textfield', + '#title' => $this->t('Model'), + '#required' => TRUE, + '#config_target' => 'materio_ai.settings:model', + ]; + $form['dimension'] = [ + '#type' => 'number', + '#title' => $this->t('Vector dimension'), + '#min' => 1, + '#required' => TRUE, + '#config_target' => 'materio_ai.settings:dimension', + ]; + $form['timeout'] = [ + '#type' => 'number', + '#title' => $this->t('Timeout (seconds)'), + '#min' => 1, + '#required' => TRUE, + '#config_target' => 'materio_ai.settings:timeout', + ]; + $form['num_thread'] = [ + '#type' => 'number', + '#title' => $this->t('Threads per call'), + '#description' => $this->t('Sent as options.num_thread: Ollama does not see the CPU limit of its container.'), + '#min' => 1, + '#required' => TRUE, + '#config_target' => 'materio_ai.settings:num_thread', + ]; + return parent::buildForm($form, $form_state); + } + +}