Core Features: - Multi-provider support (OpenAI, Anthropic, DeepSeek, Gemini, Mistral) - Provider service architecture with abstract base class - Dynamic model discovery from provider APIs - Encrypted per-user provider credentials storage Admin Interface: - Complete admin panel with Livewire components - User management with CRUD operations - API key management with testing capabilities - Budget system with limits and reset schedules - Usage logs with filtering and CSV export - Model pricing management with cost calculator - Dashboard with Chart.js visualizations Database Schema: - MariaDB migrations for all tables - User provider credentials (encrypted) - LLM request logging - Budget tracking and rate limiting - Model pricing configuration API Implementation: - OpenAI-compatible endpoints - Budget checking middleware - Rate limit enforcement - Request logging jobs - Cost calculation service Testing: - Unit tests for all provider services - Provider factory tests - Cost calculator tests Documentation: - Admin user seeder - Model pricing seeder - Configuration files
59 lines
1.3 KiB
PHP
59 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class LlmRequest extends Model
|
|
{
|
|
protected $fillable = [
|
|
'user_id',
|
|
'provider',
|
|
'model',
|
|
'request_payload',
|
|
'response_payload',
|
|
'prompt_tokens',
|
|
'completion_tokens',
|
|
'total_tokens',
|
|
'response_time_ms',
|
|
'prompt_cost',
|
|
'completion_cost',
|
|
'total_cost',
|
|
'status',
|
|
'error_message',
|
|
'http_status',
|
|
'ip_address',
|
|
'user_agent',
|
|
'request_id',
|
|
];
|
|
|
|
protected $casts = [
|
|
'request_payload' => 'array',
|
|
'response_payload' => 'array',
|
|
'prompt_tokens' => 'integer',
|
|
'completion_tokens' => 'integer',
|
|
'total_tokens' => 'integer',
|
|
'response_time_ms' => 'integer',
|
|
'prompt_cost' => 'decimal:6',
|
|
'completion_cost' => 'decimal:6',
|
|
'total_cost' => 'decimal:6',
|
|
'http_status' => 'integer',
|
|
];
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function isSuccess(): bool
|
|
{
|
|
return $this->status === 'success';
|
|
}
|
|
|
|
public function isFailed(): bool
|
|
{
|
|
return $this->status === 'failed';
|
|
}
|
|
}
|