- Issue created by @vakulrai
- Issue was unassigned.
- Status changed to RTBC
19 days ago 2:13pm 14 April 2025
My currentr setup is using:
AI module version : 1.0.4
OpenAI Provider: 1.0.2
I have observed the fatal error while saving the content after enabling automator for a body field, that uses "LLM: text" and "Default vision model" using a image field.
TypeError: Drupal\ai\OperationType\Chat\ChatMessage::__construct(): Argument #2 ($text) must be of type string, null given, called in /var/www/html/docroot/modules/contrib/ai_provider_openai/src/Plugin/AiProvider/OpenAiProvider.php on line 342 in Drupal\ai\OperationType\Chat\ChatMessage->__construct() (line 47 of modules/contrib/ai/src/OperationType/Chat/ChatMessage.php).
I saw that the response is not always returning a string , its null somtimes and then its being pased to the ChatMessage class.
$message = new ChatMessage($response['choices'][0]['message']['role'], $response['choices'][0]['message']['content']);
- Enable ai automator module
- use any content type and add a image field to the content type.
- For Text (formatted, long, with summary) e.g body field enable the automator using "LLM: text"
- use the default vision model and chose the image field type under provider configuration.
- make sure you add a promt for the field.
- save the settings and create a new node for the same. (The issue is appearing intermittently)
adding a null coalescing operator to this line has fixed the issue:
$message = new ChatMessage($response['choices'][0]['message']['role'], $response['choices'][0]['message']['content']);
Active
1.0
Code