jofitz: Drupal AI: first steps

Artificial Intelligence has arrived in the Drupal ecosystem and it is already making huge waves. This is the first in a series of articles about my experiences as I dip a toe into these exciting waters.

The task

I was working on a large website with plenty of content dating back years, including numerous product reviews that required improved categorisation. The goal was to tag all of these review nodes with the relevant Make and Model.

The approach

I chose to write a custom Drush script to loop through all of the review nodes, using Artificial Intelligence to parse the Title and Body fields and return the make and model discussed therein.

public function reviewsMakeModel(): void { $fields = ['title', 'body']; foreach ($review_nodes as $review_node) { $data = []; foreach ($fields as $field) { $data[] = $review_node->get($field)->value; } $text = implode("\n", $data); $makeAndModel = $this->getMakeAndModel($text); // More to follow... } }

The provider

I...

Read more
PubDate

Tags