- AiLogger.php: new service, inserts into ai_logs on every AI call - ai_logs table: added to migrate.php (provider, model, call_type, tokens, duration_ms) - AiBot: logs chat, media_response, nlu calls with timing and token counts - MediaTranscriber: logs whisper, geminiAudio, openaiVision, geminiVision, claudeVision - /admin/ai-logs: paginated table with provider/company filter - Layout.php: added IA Logs nav link - index.php: require AiLogger before AiBot; added GET /admin/ai-logs route Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
class AiLogger
|
|
{
|
|
public static function log(
|
|
?int $companyId,
|
|
string $provider,
|
|
string $model,
|
|
string $callType,
|
|
string $inputPreview,
|
|
string $outputPreview,
|
|
int $durationMs,
|
|
string $phone = '',
|
|
?int $tokensIn = null,
|
|
?int $tokensOut = null
|
|
): void {
|
|
try {
|
|
db()->prepare("
|
|
INSERT INTO ai_logs
|
|
(company_id, phone_number, provider, model, call_type,
|
|
input_preview, output_preview, tokens_in, tokens_out, duration_ms)
|
|
VALUES (?,?,?,?,?,?,?,?,?,?)
|
|
")->execute([
|
|
$companyId ?: null,
|
|
$phone !== '' ? $phone : null,
|
|
$provider,
|
|
$model,
|
|
$callType,
|
|
mb_substr($inputPreview, 0, 500),
|
|
mb_substr($outputPreview, 0, 500),
|
|
$tokensIn,
|
|
$tokensOut,
|
|
$durationMs,
|
|
]);
|
|
} catch (\Throwable) {
|
|
// Never break the bot for a log failure
|
|
}
|
|
}
|
|
}
|