I migrated an existing website to another server and since then we cannot create content where there is an automator.
Error is:
TypeError: array_map(): Argument #2 ($array) must be of type array, null given in array_map() (line 44 of /home/vendor/openai-php/client/src/Responses/Moderations/CreateResponse.php).
OPenai proposed to change the code to:
public function moderationEndpoints(string $prompt): void {
$this->getClient();
// If moderation is disabled, skip entirely.
if ($this->moderation !== TRUE) {
return;
}
$payload = [
'model' => 'omni-moderation-latest',
'input' => $prompt,
] + $this->configuration;
try {
$response = $this->client->moderations()->create($payload)->toArray();
}
catch (\Exception $e) {
if (str_contains($e->getMessage(), 'Request too large') ||
str_contains($e->getMessage(), 'Too Many Requests')) {
throw new AiRateLimitException($e->getMessage());
}
if (str_contains($e->getMessage(), 'You exceeded your current quota')) {
throw new AiQuotaException($e->getMessage());
}
throw $e;
}
// 🔒 HARD SAFETY CHECK (this is what was missing)
if (
empty($response['results']) ||
!is_array($response['results']) ||
empty($response['results'][0]) ||
!is_array($response['results'][0])
) {
// Log and silently allow (fail-open, NOT fail-hard)
$this->logger->warning(
'OpenAI moderation returned an unexpected response structure.',
['response' => $response]
);
return;
}
if (!empty($response['results'][0]['flagged'])) {
throw new AiUnsafePromptException('The prompt was flagged by the moderation model.');
}
}
And it looks to work.
Did you ever change anything in the update? Thanks!
Comments
Comment #2
nodles commentedI got the same error, and updating the client library https://github.com/openai-php/client the error disappear