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,158 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
class ModelPricingSeeder extends Seeder
{
public function run(): void
{
$now = Carbon::now();
$pricingData = [
// OpenAI Models
[
'provider' => 'openai',
'model' => 'gpt-4o',
'input_price_per_million' => 2.50,
'output_price_per_million' => 10.00,
'context_window' => 128000,
'max_output_tokens' => 16384,
'is_active' => true,
'effective_from' => $now->toDateString(),
'notes' => 'GPT-4 Omni - Most capable model',
'created_at' => $now,
'updated_at' => $now,
],
[
'provider' => 'openai',
'model' => 'gpt-4o-mini',
'input_price_per_million' => 0.15,
'output_price_per_million' => 0.60,
'context_window' => 128000,
'max_output_tokens' => 16384,
'is_active' => true,
'effective_from' => $now->toDateString(),
'notes' => 'Cost-efficient model for simple tasks',
'created_at' => $now,
'updated_at' => $now,
],
[
'provider' => 'openai',
'model' => 'gpt-4-turbo',
'input_price_per_million' => 10.00,
'output_price_per_million' => 30.00,
'context_window' => 128000,
'max_output_tokens' => 4096,
'is_active' => true,
'effective_from' => $now->toDateString(),
'notes' => 'GPT-4 Turbo with vision capabilities',
'created_at' => $now,
'updated_at' => $now,
],
[
'provider' => 'openai',
'model' => 'gpt-3.5-turbo',
'input_price_per_million' => 0.50,
'output_price_per_million' => 1.50,
'context_window' => 16385,
'max_output_tokens' => 4096,
'is_active' => true,
'effective_from' => $now->toDateString(),
'notes' => 'Fast and affordable legacy model',
'created_at' => $now,
'updated_at' => $now,
],
// Anthropic Models
[
'provider' => 'anthropic',
'model' => 'claude-opus-4',
'input_price_per_million' => 15.00,
'output_price_per_million' => 75.00,
'context_window' => 200000,
'max_output_tokens' => 4096,
'is_active' => true,
'effective_from' => $now->toDateString(),
'notes' => 'Most capable Claude model',
'created_at' => $now,
'updated_at' => $now,
],
[
'provider' => 'anthropic',
'model' => 'claude-sonnet-4',
'input_price_per_million' => 3.00,
'output_price_per_million' => 15.00,
'context_window' => 200000,
'max_output_tokens' => 8192,
'is_active' => true,
'effective_from' => $now->toDateString(),
'notes' => 'Balanced performance and cost',
'created_at' => $now,
'updated_at' => $now,
],
[
'provider' => 'anthropic',
'model' => 'claude-haiku-4',
'input_price_per_million' => 0.25,
'output_price_per_million' => 1.25,
'context_window' => 200000,
'max_output_tokens' => 4096,
'is_active' => true,
'effective_from' => $now->toDateString(),
'notes' => 'Fast and cost-effective',
'created_at' => $now,
'updated_at' => $now,
],
// Mistral AI Models
[
'provider' => 'mistral',
'model' => 'mistral-large',
'input_price_per_million' => 2.00,
'output_price_per_million' => 6.00,
'context_window' => 128000,
'max_output_tokens' => 4096,
'is_active' => true,
'effective_from' => $now->toDateString(),
'notes' => 'Most capable Mistral model',
'created_at' => $now,
'updated_at' => $now,
],
[
'provider' => 'mistral',
'model' => 'mistral-medium',
'input_price_per_million' => 2.70,
'output_price_per_million' => 8.10,
'context_window' => 32000,
'max_output_tokens' => 4096,
'is_active' => true,
'effective_from' => $now->toDateString(),
'notes' => 'Balanced Mistral model',
'created_at' => $now,
'updated_at' => $now,
],
[
'provider' => 'mistral',
'model' => 'mistral-small',
'input_price_per_million' => 0.20,
'output_price_per_million' => 0.60,
'context_window' => 32000,
'max_output_tokens' => 4096,
'is_active' => true,
'effective_from' => $now->toDateString(),
'notes' => 'Cost-effective Mistral model',
'created_at' => $now,
'updated_at' => $now,
],
];
DB::table('model_pricing')->insert($pricingData);
$this->command->info('Model pricing data seeded successfully!');
$this->command->info('Total models: ' . count($pricingData));
}
}