72 lines
1.4 KiB
PHP
72 lines
1.4 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 文件功能:AI 使用日志模型
|
|||
|
|
*
|
|||
|
|
* 对应 ai_usage_logs 表,记录每次 AI 接口调用的详细信息,
|
|||
|
|
* 包括 token 消耗、响应时间、成功/失败状态等。
|
|||
|
|
*
|
|||
|
|
* @author ChatRoom Laravel
|
|||
|
|
*
|
|||
|
|
* @version 1.0.0
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
namespace App\Models;
|
|||
|
|
|
|||
|
|
use Illuminate\Database\Eloquent\Model;
|
|||
|
|
|
|||
|
|
class AiUsageLog extends Model
|
|||
|
|
{
|
|||
|
|
/**
|
|||
|
|
* 关联的数据库表名
|
|||
|
|
*
|
|||
|
|
* @var string
|
|||
|
|
*/
|
|||
|
|
protected $table = 'ai_usage_logs';
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 可批量赋值的属性
|
|||
|
|
*
|
|||
|
|
* @var array<int, string>
|
|||
|
|
*/
|
|||
|
|
protected $fillable = [
|
|||
|
|
'company_id',
|
|||
|
|
'user_id',
|
|||
|
|
'provider',
|
|||
|
|
'model',
|
|||
|
|
'action',
|
|||
|
|
'prompt_tokens',
|
|||
|
|
'completion_tokens',
|
|||
|
|
'total_tokens',
|
|||
|
|
'cost',
|
|||
|
|
'response_time_ms',
|
|||
|
|
'success',
|
|||
|
|
'error_message',
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 属性类型转换
|
|||
|
|
*
|
|||
|
|
* @return array<string, string>
|
|||
|
|
*/
|
|||
|
|
protected function casts(): array
|
|||
|
|
{
|
|||
|
|
return [
|
|||
|
|
'prompt_tokens' => 'integer',
|
|||
|
|
'completion_tokens' => 'integer',
|
|||
|
|
'total_tokens' => 'integer',
|
|||
|
|
'cost' => 'float',
|
|||
|
|
'response_time_ms' => 'integer',
|
|||
|
|
'success' => 'boolean',
|
|||
|
|
];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 关联用户
|
|||
|
|
*/
|
|||
|
|
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|||
|
|
{
|
|||
|
|
return $this->belongsTo(User::class);
|
|||
|
|
}
|
|||
|
|
}
|