PHP error when complex response can't be decoded

Created on 25 October 2024, 21 days ago

Problem/Motivation

I'm using automators to create content based on fields and paragraphs of a node.

When i save the node to populate my field, i end up with the following error :

Error: Cannot use object of type Drupal\ai\OperationType\Chat\ChatMessage as array in Drupal\ai_automators\PluginBaseClasses\RuleBase->decodeValueArray() (regel 634 van /var/www/html/web/modules/contrib/ai/modules/ai_automators/src/PluginBaseClasses/RuleBase.php).

It seems to be linked to the "decodePayload()" method.

The method dont succeed to parse the JSON that comes from the AI and send null.

Wich endup in the runChatMessage method Where "$this->promptJsonDecoder->decode($text))" is a ChatMessage and not an array as expected.

Steps to reproduce

Create a field that uses automators to create a complex answer.
prompt like :
```
You are a article writter for websites and you will helping me by creating an article for my website.
Write me a complete article for the activity described bellow.
Please ignore empty fields.
Here are the title of the activity :
[node:title]
Here is the page description of the activity :
[node:field_udb_description:value]
Here is the Typical age range :
[node:field_udb_typical_age_range:value]
Here is the Date :
[node:field_udb_date:value] - [node:field_udb_date:end_value]
Here is the Location address :
[node:field_udb_location_address:address_line1]
[node:field_udb_location_address:address_line2]
[node:field_udb_location_address:postal_code] [node:field_udb_location_address:locality]
[node:field_udb_location_address:country_name]

```

Proposed resolution

Imporve the sanitazation of the json received fom API in decodePayload() method

🐛 Bug report
Status

Active

Version

1.0

Component

AI Automators

Created by

🇧🇪Belgium arwillame

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024