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:
208
laravel-app/resources/views/admin/credentials/edit.blade.php
Normal file
208
laravel-app/resources/views/admin/credentials/edit.blade.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<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">
|
||||
{{ __('Edit Provider Credentials') }}
|
||||
</h2>
|
||||
<div class="space-x-2">
|
||||
<a href="{{ route('admin.credentials.show', $credential) }}" class="bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded">
|
||||
View Details
|
||||
</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-3xl mx-auto sm:px-6 lg:px-8">
|
||||
@if(session('error'))
|
||||
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
|
||||
{{ session('error') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<form method="POST" action="{{ route('admin.credentials.update', $credential) }}" class="space-y-6">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<!-- User (Read-only) -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-2">
|
||||
User
|
||||
</label>
|
||||
<div class="w-full px-3 py-2 bg-gray-100 rounded-md border border-gray-300">
|
||||
<div class="font-medium">{{ $credential->user->name }}</div>
|
||||
<div class="text-sm text-gray-500">{{ $credential->user->email }}</div>
|
||||
</div>
|
||||
<p class="text-xs text-gray-500 mt-1">
|
||||
User cannot be changed after creation
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Provider (Read-only) -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-2">
|
||||
AI Provider
|
||||
</label>
|
||||
<div class="w-full px-3 py-2 bg-gray-100 rounded-md border border-gray-300">
|
||||
<span class="inline-flex items-center px-3 py-1 rounded-full text-sm 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">
|
||||
{{ $providers[$credential->provider] ?? ucfirst($credential->provider) }}
|
||||
</span>
|
||||
</div>
|
||||
<p class="text-xs text-gray-500 mt-1">
|
||||
Provider cannot be changed after creation
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- API Key (Update) -->
|
||||
<div>
|
||||
<label for="api_key" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
API Key <span class="text-gray-400">(leave empty to keep current)</span>
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
name="api_key"
|
||||
id="api_key"
|
||||
placeholder="sk-... (enter new key to update)"
|
||||
class="w-full rounded-md border-gray-300 @error('api_key') border-red-500 @enderror"
|
||||
value="{{ old('api_key') }}"
|
||||
>
|
||||
@error('api_key')
|
||||
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
|
||||
@enderror
|
||||
<p class="text-xs text-gray-500 mt-1">
|
||||
🔒 Current API key is encrypted and hidden. Enter a new key only if you want to update it.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Organization ID -->
|
||||
<div>
|
||||
<label for="organization_id" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
Organization ID <span class="text-gray-400">(optional)</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="organization_id"
|
||||
id="organization_id"
|
||||
placeholder="org-..."
|
||||
class="w-full rounded-md border-gray-300 @error('organization_id') border-red-500 @enderror"
|
||||
value="{{ old('organization_id', $credential->organization_id) }}"
|
||||
>
|
||||
@error('organization_id')
|
||||
<p class="text-red-500 text-xs mt-1">{{ $message }}</p>
|
||||
@enderror
|
||||
<p class="text-xs text-gray-500 mt-1">
|
||||
Required for some OpenAI enterprise accounts
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Active Status -->
|
||||
<div class="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="is_active"
|
||||
id="is_active"
|
||||
value="1"
|
||||
{{ old('is_active', $credential->is_active) ? 'checked' : '' }}
|
||||
class="rounded border-gray-300 text-blue-600 shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200 focus:ring-opacity-50"
|
||||
>
|
||||
<label for="is_active" class="ml-2 block text-sm text-gray-900">
|
||||
Active (enable for use in requests)
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- Metadata Info -->
|
||||
<div class="bg-gray-50 rounded-lg p-4">
|
||||
<h3 class="font-semibold text-gray-900 mb-2">Metadata</h3>
|
||||
<div class="grid grid-cols-2 gap-4 text-sm">
|
||||
<div>
|
||||
<span class="text-gray-600">Created:</span>
|
||||
<span class="font-medium">{{ $credential->created_at->format('M d, Y H:i') }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-600">Last Updated:</span>
|
||||
<span class="font-medium">{{ $credential->updated_at->format('M d, Y H:i') }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-600">Last Used:</span>
|
||||
<span class="font-medium">{{ $credential->last_used_at ? $credential->last_used_at->diffForHumans() : 'Never' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Submit Button -->
|
||||
<div class="flex items-center justify-end space-x-3">
|
||||
<a href="{{ route('admin.credentials.index') }}" class="bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded">
|
||||
Cancel
|
||||
</a>
|
||||
<button
|
||||
type="button"
|
||||
onclick="testCredential({{ $credential->id }})"
|
||||
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
🧪 Test Current Key
|
||||
</button>
|
||||
<button type="submit" class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
|
||||
Update Credentials
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Info Box -->
|
||||
<div class="mt-6 bg-yellow-50 border border-yellow-200 rounded-lg p-4">
|
||||
<h3 class="font-semibold text-yellow-900 mb-2">⚠️ Important Notes</h3>
|
||||
<ul class="text-sm text-yellow-800 space-y-1 list-disc list-inside">
|
||||
<li>User and Provider cannot be changed once created</li>
|
||||
<li>Test the API key before saving to ensure it works</li>
|
||||
<li>Old API key will be replaced if you enter a new one</li>
|
||||
<li>Disabling credentials will prevent any API requests using this key</li>
|
||||
</ul>
|
||||
</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