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:
29
laravel-app/database/seeders/AdminUserSeeder.php
Normal file
29
laravel-app/database/seeders/AdminUserSeeder.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AdminUserSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
User::firstOrCreate(
|
||||
['email' => 'admin@example.com'],
|
||||
[
|
||||
'name' => 'Admin User',
|
||||
'password' => Hash::make('password'),
|
||||
'email_verified_at' => now(),
|
||||
]
|
||||
);
|
||||
|
||||
$this->command->info('Admin user created successfully!');
|
||||
$this->command->info('Email: admin@example.com');
|
||||
$this->command->info('Password: password');
|
||||
}
|
||||
}
|
||||
158
laravel-app/database/seeders/ModelPricingSeeder.php
Normal file
158
laravel-app/database/seeders/ModelPricingSeeder.php
Normal 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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user