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:
232
laravel-app/resources/views/admin/credentials/show.blade.php
Normal file
232
laravel-app/resources/views/admin/credentials/show.blade.php
Normal file
@@ -0,0 +1,232 @@
|
||||
<x-app-layout>
|
||||
<x-slot name="header">
|
||||
<div class="flex justify-between items-center">
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
|
||||
{{ __('Provider Credentials Details') }}
|
||||
</h2>
|
||||
<div class="space-x-2">
|
||||
<button
|
||||
onclick="testCredential({{ $credential->id }})"
|
||||
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
🧪 Test API Key
|
||||
</button>
|
||||
<a href="{{ route('admin.credentials.edit', $credential) }}" class="bg-yellow-500 hover:bg-yellow-700 text-white font-bold py-2 px-4 rounded">
|
||||
Edit
|
||||
</a>
|
||||
<a href="{{ route('admin.credentials.index') }}" class="bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded">
|
||||
Back to List
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</x-slot>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
|
||||
|
||||
<!-- Basic Information -->
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<h3 class="text-lg font-semibold mb-4">Basic Information</h3>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<!-- User -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">User</label>
|
||||
<div class="text-lg font-semibold">{{ $credential->user->name }}</div>
|
||||
<div class="text-sm text-gray-500">{{ $credential->user->email }}</div>
|
||||
</div>
|
||||
|
||||
<!-- Provider -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Provider</label>
|
||||
<span class="inline-flex items-center px-4 py-2 rounded-full text-base font-medium
|
||||
@if($credential->provider == 'openai') bg-green-100 text-green-800
|
||||
@elseif($credential->provider == 'anthropic') bg-purple-100 text-purple-800
|
||||
@elseif($credential->provider == 'mistral') bg-blue-100 text-blue-800
|
||||
@elseif($credential->provider == 'gemini') bg-yellow-100 text-yellow-800
|
||||
@else bg-gray-100 text-gray-800
|
||||
@endif">
|
||||
{{ ucfirst($credential->provider) }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Organization ID -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Organization ID</label>
|
||||
<div class="text-base">{{ $credential->organization_id ?? 'Not set' }}</div>
|
||||
</div>
|
||||
|
||||
<!-- Status -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Status</label>
|
||||
@if($credential->is_active)
|
||||
<span class="px-4 inline-flex text-base leading-7 font-semibold rounded-full bg-green-100 text-green-800">
|
||||
✓ Active
|
||||
</span>
|
||||
@else
|
||||
<span class="px-4 inline-flex text-base leading-7 font-semibold rounded-full bg-red-100 text-red-800">
|
||||
✗ Inactive
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<!-- Created At -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Created</label>
|
||||
<div class="text-base">{{ $credential->created_at->format('M d, Y H:i') }}</div>
|
||||
<div class="text-sm text-gray-500">{{ $credential->created_at->diffForHumans() }}</div>
|
||||
</div>
|
||||
|
||||
<!-- Last Used -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Last Used</label>
|
||||
<div class="text-base">
|
||||
@if($credential->last_used_at)
|
||||
{{ $credential->last_used_at->format('M d, Y H:i') }}
|
||||
<div class="text-sm text-gray-500">{{ $credential->last_used_at->diffForHumans() }}</div>
|
||||
@else
|
||||
<span class="text-gray-500">Never used</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Usage Statistics -->
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<h3 class="text-lg font-semibold mb-4">Usage Statistics</h3>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||
<!-- Total Requests -->
|
||||
<div class="bg-blue-50 rounded-lg p-4">
|
||||
<div class="text-sm text-blue-600 font-medium">Total Requests</div>
|
||||
<div class="text-2xl font-bold text-blue-900">{{ number_format($stats['total_requests']) }}</div>
|
||||
</div>
|
||||
|
||||
<!-- Total Cost -->
|
||||
<div class="bg-green-50 rounded-lg p-4">
|
||||
<div class="text-sm text-green-600 font-medium">Total Cost</div>
|
||||
<div class="text-2xl font-bold text-green-900">${{ number_format($stats['total_cost'], 2) }}</div>
|
||||
</div>
|
||||
|
||||
<!-- Total Tokens -->
|
||||
<div class="bg-purple-50 rounded-lg p-4">
|
||||
<div class="text-sm text-purple-600 font-medium">Total Tokens</div>
|
||||
<div class="text-2xl font-bold text-purple-900">{{ number_format($stats['total_tokens']) }}</div>
|
||||
</div>
|
||||
|
||||
<!-- Last 30 Days -->
|
||||
<div class="bg-yellow-50 rounded-lg p-4">
|
||||
<div class="text-sm text-yellow-600 font-medium">Last 30 Days</div>
|
||||
<div class="text-2xl font-bold text-yellow-900">{{ number_format($stats['last_30_days_requests']) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Security Information -->
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<h3 class="text-lg font-semibold mb-4">Security Information</h3>
|
||||
|
||||
<div class="space-y-3">
|
||||
<div class="flex items-start">
|
||||
<span class="text-green-500 text-xl mr-3">🔒</span>
|
||||
<div>
|
||||
<div class="font-medium">Encryption Status</div>
|
||||
<div class="text-sm text-gray-600">API key is encrypted using AES-256-CBC encryption</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-start">
|
||||
<span class="text-blue-500 text-xl mr-3">🔑</span>
|
||||
<div>
|
||||
<div class="font-medium">API Key Format</div>
|
||||
<div class="text-sm text-gray-600">
|
||||
<code class="bg-gray-100 px-2 py-1 rounded">{{ $credential->provider }}-*********************</code>
|
||||
(hidden for security)
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-start">
|
||||
<span class="text-purple-500 text-xl mr-3">📊</span>
|
||||
<div>
|
||||
<div class="font-medium">Usage Tracking</div>
|
||||
<div class="text-sm text-gray-600">All requests using this credential are logged and tracked</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<h3 class="text-lg font-semibold mb-4">Actions</h3>
|
||||
|
||||
<div class="flex space-x-3">
|
||||
<button
|
||||
onclick="testCredential({{ $credential->id }})"
|
||||
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
🧪 Test API Key
|
||||
</button>
|
||||
|
||||
<a href="{{ route('admin.credentials.edit', $credential) }}" class="bg-yellow-500 hover:bg-yellow-700 text-white font-bold py-2 px-4 rounded">
|
||||
✏️ Edit Credentials
|
||||
</a>
|
||||
|
||||
<form
|
||||
action="{{ route('admin.credentials.destroy', $credential) }}"
|
||||
method="POST"
|
||||
onsubmit="return confirm('Are you sure you want to delete these credentials? This action cannot be undone.');"
|
||||
class="inline">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded">
|
||||
🗑️ Delete Credentials
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
function testCredential(credentialId) {
|
||||
const button = event.target;
|
||||
const originalText = button.textContent;
|
||||
button.textContent = '🔄 Testing...';
|
||||
button.disabled = true;
|
||||
|
||||
fetch(`/admin/credentials/${credentialId}/test`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
alert(`✅ Success!\n\n${data.message}\n${data.details || ''}`);
|
||||
} else {
|
||||
alert(`❌ Failed!\n\n${data.message}`);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert(`❌ Error!\n\n${error.message}`);
|
||||
})
|
||||
.finally(() => {
|
||||
button.textContent = originalText;
|
||||
button.disabled = false;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
</x-app-layout>
|
||||
Reference in New Issue
Block a user