- Migration + AiUsageLog model with tokens, duration, time, cost fields - GeminiIntentService and GeminiVisionService log every API call with input/output token counts from usageMetadata and response time - TelegramBotService logs Whisper calls with audio duration (from Telegram) and calculates cost at $1/second - Whisper voice duration now passed from TelegramWebhookController - Free text in Telegram now tries Gemini intent detection before showing menu - /chat/ia-logs: Livewire component with summary cards + filterable table - Whisper connection test button in config panel - "Logs IA" link added to Chat/Bot nav section Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
28 lines
610 B
PHP
28 lines
610 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class AiUsageLog extends Model
|
|
{
|
|
protected $table = 'ai_usage_logs';
|
|
|
|
protected $fillable = [
|
|
'servicio', 'canal', 'usuario_id',
|
|
'input_tokens', 'output_tokens', 'audio_segundos',
|
|
'tiempo_ms', 'costo', 'resultado', 'detalle',
|
|
];
|
|
|
|
protected $casts = ['detalle' => 'array'];
|
|
|
|
public static function registrar(array $data): void
|
|
{
|
|
try {
|
|
static::create($data);
|
|
} catch (\Throwable) {
|
|
// No interrumpir el flujo principal si el log falla
|
|
}
|
|
}
|
|
}
|