Problem/Motivation
I am getting this error in the log messages:
Deprecated function: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in Drupal\ai_assistant_api\Service\AssistantMessageBuilder->buildMessage() (line 110 of /var/www/html/web/modules/contrib/ai/modules/ai_assistant_api/src/Service/AssistantMessageBuilder.php)
Solution:
This is a PHP 8.1+ deprecation warning to ensure the placeholders are safely replaced.
To fix this you can convert NULL to an empty string before calling str_replace().
Steps to reproduce
I am using Core 11.1.2 and AI module version 1.0.4.
Issue fork ai-3505215
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
torfjI am a MR with the changes that will convert NULL to an empty string before calling str_replace().
Comment #4
mrdalesmith commentedI'm not sure that's the way to go: if the $this->prePrompt() is empty you're just going to get the same error: it might be better if we check if the values exist before passing them to str_replace()?
Comment #6
anjaliprasannan commentedComment #7
anjaliprasannan commentedComment #8
annmarysruthy commentedReviewed the MR !460. The error message could not be replicated after the changes in MR. AI Assistant is also working fine.
Comment #9
annmarysruthy commentedComment #11
robloachWorked well here. I added a small tweak so that it doesn't call
prePrompt()twice. This applies to both 1.1.x and 1.0.x.Comment #12
marcus_johansson commentedThank you, getting merged.