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

Command icon 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

torfj created an issue. See original summary.

torfj’s picture

I am a MR with the changes that will convert NULL to an empty string before calling str_replace().

mrdalesmith’s picture

I'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()?

anjaliprasannan made their first commit to this issue’s fork.

anjaliprasannan’s picture

Assigned: torfj » anjaliprasannan
Status: Active » Needs review
anjaliprasannan’s picture

Assigned: anjaliprasannan » Unassigned
annmarysruthy’s picture

Assigned: Unassigned » annmarysruthy

Reviewed the MR !460. The error message could not be replicated after the changes in MR. AI Assistant is also working fine.

annmarysruthy’s picture

Assigned: annmarysruthy » Unassigned

robloach made their first commit to this issue’s fork.

robloach’s picture

Status: Needs review » Reviewed & tested by the community

Worked 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.

marcus_johansson’s picture

Version: 1.1.x-dev » 1.0.x-dev
Status: Reviewed & tested by the community » Fixed

Thank you, getting merged.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.