AI Interpolator

A framework module that enables automatic population of entity fields using AI-based processing from source text fields.

ai_interpolator
106 sites
43
drupal.org

概要

AI Interpolatorは、AIサービスを使用してDrupal Entityフィールドを自動的に入力するための強力なPluginベースのフレームワークを提供します。このモジュールはソースフィールド(通常はテキストフィールド)からコンテンツを読み取り、AIを使用してさまざまなタイプのターゲットフィールドに適切な値を生成します。

このモジュール自体にはAIプロバイダーは含まれていません。他のモジュールが特定のAI実装(OpenAI、Claudeなど)で拡張できるフレームワークとして機能します。このアーキテクチャにより、サイトビルダーは一貫したフィールド設定インターフェースを維持しながら、好みのAIサービスを選択できます。

主なアーキテクチャ機能:

  • Pluginベースのフィールドルール: AIを使用してさまざまなフィールドタイプをどのように入力するかを定義するための拡張可能なシステム
  • 複数の処理方法: 直接同期処理、JavaScriptバッチ処理、またはCronを介したQueueベースの非同期処理をサポート
  • イベントシステム: さまざまな段階で補間動作をインターセプトおよび変更するための包括的なイベント
  • Tokenサポート: 動的なプロンプト生成のためのDrupal Tokenを使用した高度なモード
  • ステータス追跡: 補間の進行状況(pending、processing、failed、finished)を追跡するための自動ステータスフィールド

Features

  • さまざまなフィールドタイプ(テキスト、Taxonomy、ブール値、数値、Entity Reference、画像、リンク、オプションなど)のAIフィールドルールを定義するためのPluginベースのアーキテクチャ
  • 3つの処理モード:Direct(同期)、Batch(JavaScriptベース)、Queue/Cron(非同期バックグラウンド処理)
  • 補間が有効なEntityの自動ステータスフィールド追跡(pending、processing、failed、finished)
  • Baseモード:Twigスタイルのプレースホルダーを使用したカスタマイズ可能なプロンプトでソースフィールドのコンテンツを使用
  • 高度なTokenモード:Entityデータに基づく動的なプロンプト生成のためのDrupal Tokenモジュールとの統合
  • 補間されたフィールド間の依存関係を処理するための重み付けベースのフィールド処理順序
  • ソースコンテンツが変更されたときにフィールドを再補間する編集モードオプション
  • SimpleTextChat、ComplexTextChat、Taxonomy、Boolean、Numeric、Options、Lists、Link、EntityReference、TextToImage、ImageToImageなど、一般的なフィールドタイプルール用の20の事前構築ベースクラス
  • 設定、フィールド処理、ルールの可視性、値の変更、詳細情報をカスタマイズするための5つのイベントを備えたイベント駆動アーキテクチャ
  • 一般的な操作のためのヘルパーサービス:JSON解析、LLMパラメータ、ファイル処理、画像スタイル前処理、テキスト結合
  • カスタム非AIルールを作成するためのサンプルPlugin実装を含む

Use Cases

Automatic Taxonomy Tagging

Configure a taxonomy term reference field to be automatically populated based on article body content. The AI analyzes the text and selects or creates appropriate tags from the configured vocabulary. Supports auto-creation of new terms when enabled, text manipulation (lowercase, uppercase, first character uppercase), and similar tag matching to avoid duplicates.

Content Summarization

Set up a summary text field that automatically generates an executive summary from a long-form body field. Use the SimpleTextChat base class with a prompt like 'Summarize the following content in 2-3 sentences: {{ context }}'. The summary is generated when content is saved.

Sentiment Analysis

Add a list field with sentiment options (positive, negative, neutral) and configure AI Interpolator with the Options base class to automatically analyze and categorize content sentiment based on the body text.

AI-Generated Featured Images

Use the TextToImage base class (requires AI image generation sub-module) to automatically generate featured images based on article titles or descriptions. The AI creates images matching the content theme.

Automated SEO Meta Fields

Configure string fields for meta titles and descriptions to be auto-generated from the main content. Use prompts that instruct the AI to create SEO-optimized text within character limits.

Entity Reference Population

Automatically create and link related entities based on source content. The EntityReference base class can parse content and generate child entities with multiple fields populated by AI.

Boolean Field Classification

Add boolean fields that automatically classify content based on AI analysis. For example, 'Contains Personal Data' or 'Is Time-Sensitive' flags that the AI determines from content analysis.

Numeric Scoring

Use the Numeric base class to have AI assign numeric scores or ratings to content. Respects min/max field settings and validates numeric output.

Link Extraction

Automatically extract and store URLs mentioned in content using the Link base class. The AI identifies links and their context to populate link fields with URI and title.

Asynchronous Bulk Processing

Use Queue/Cron processing mode for importing large amounts of content where AI processing time would cause timeouts. Content is saved immediately with 'pending' status, and AI fields are populated in the background via cron.

Tips

  • Always install at least one AI provider sub-module - the base AI Interpolator module provides the framework but no actual AI functionality
  • Use Queue/Cron processing mode for production sites with slow AI APIs to avoid HTTP timeouts during content editing
  • Set appropriate weights when multiple fields depend on each other's interpolated values - lower weights process first
  • Enable 'Edit when changed' carefully as it will re-process fields on every save when the source field changes
  • Use Advanced Token Mode when you need to include data from referenced entities or complex entity relationships in prompts
  • The status field (ai_interpolator_status) is automatically added to entity bundles when any field has interpolation enabled - use it to filter or display processing status
  • Test prompts thoroughly with representative content before enabling on production - AI responses can vary significantly based on prompt wording
  • Consider creating custom rules without AI for simple transformations (like the StripTags example) to avoid unnecessary API calls
  • Use the GeneralHelper service's parseJson() method when creating rules that expect JSON responses from AI
  • Subscribe to the ai_interpolator.change_value event to post-process AI responses before storage, such as additional validation or formatting

Technical Details

Admin Pages 1
Field Configuration /admin/structure/types/manage/{bundle}/fields/{field_config}

AI Interpolator adds settings to field configuration forms when applicable rules exist for the field type. The settings appear as an 'Enable AI Interpolator' checkbox that reveals additional configuration options when checked.

Hooks 2
hook_ai_interpolator_field_rule_alter

Alter the discovered field rule plugin definitions

hook_ai_interpolator_process_alter

Alter the discovered process rule plugin definitions