24 lines
832 B
PHP
24 lines
832 B
PHP
<?php
|
|
require_once __DIR__ . '/../ai/LocalAIApi.php';
|
|
|
|
function moderateContent($content) {
|
|
if (empty(trim($content))) return ['is_safe' => true];
|
|
|
|
$resp = LocalAIApi::createResponse([
|
|
'input' => [
|
|
['role' => 'system', 'content' => 'You are a content moderator. Analyze the message and return a JSON object with "is_safe" (boolean) and "reason" (string, optional). Safe means no hate speech, extreme violence, or explicit sexual content.'],
|
|
['role' => 'user', 'content' => $content],
|
|
],
|
|
]);
|
|
|
|
if (!empty($resp['success'])) {
|
|
$result = LocalAIApi::decodeJsonFromResponse($resp);
|
|
if ($result && isset($result['is_safe'])) {
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
// Default to safe if AI fails, to avoid blocking users
|
|
return ['is_safe' => true];
|
|
}
|