Add complete Laravel LLM Gateway implementation

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
This commit is contained in:
wtrinkl
2025-11-18 22:18:36 +01:00
parent bef36c7ca2
commit 6573e15ba4
60 changed files with 5991 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Exceptions;
use Exception;
class InsufficientBudgetException extends Exception
{
protected $code = 402; // Payment Required
public function __construct(string $message = "Insufficient budget", int $code = 402, ?Exception $previous = null)
{
parent::__construct($message, $code, $previous);
}
/**
* Render the exception as an HTTP response.
*/
public function render()
{
return response()->json([
'success' => false,
'error' => 'budget_exceeded',
'message' => $this->getMessage(),
], $this->code);
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Exceptions;
use Exception;
class ProviderException extends Exception
{
public function __construct(string $message = "Provider error", int $code = 500, ?Exception $previous = null)
{
parent::__construct($message, $code, $previous);
}
/**
* Render the exception as an HTTP response.
*/
public function render()
{
return response()->json([
'success' => false,
'error' => 'provider_error',
'message' => $this->getMessage(),
], $this->code);
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Exceptions;
use Exception;
class RateLimitExceededException extends Exception
{
protected $code = 429; // Too Many Requests
public function __construct(string $message = "Rate limit exceeded", int $code = 429, ?Exception $previous = null)
{
parent::__construct($message, $code, $previous);
}
/**
* Render the exception as an HTTP response.
*/
public function render()
{
return response()->json([
'success' => false,
'error' => 'rate_limit_exceeded',
'message' => $this->getMessage(),
], $this->code);
}
}