Initial commit: Any-LLM Gateway with Laravel Admin Interface
- Any-LLM Gateway setup with Docker Compose - Laravel 11 admin interface with Livewire - Dashboard with usage statistics and charts - Gateway Users management with budget tracking - API Keys management with revocation - Budget templates with assignment - Usage Logs with filtering and CSV export - Model Pricing management with calculator - PostgreSQL database integration - Complete authentication system for admins
This commit is contained in:
138
laravel-app/resources/views/model-pricing/calculator.blade.php
Normal file
138
laravel-app/resources/views/model-pricing/calculator.blade.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<x-app-layout>
|
||||
<x-slot name="header">
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
|
||||
Cost Calculator
|
||||
</h2>
|
||||
</x-slot>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-3xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<p class="text-sm text-gray-600 mb-6">
|
||||
Calculate the cost of API requests based on token usage and model pricing.
|
||||
</p>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label for="calc_model" class="block text-sm font-medium text-gray-700 mb-1">
|
||||
Select Model *
|
||||
</label>
|
||||
<select id="calc_model"
|
||||
class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
||||
<option value="">Choose a model...</option>
|
||||
@foreach($models as $model)
|
||||
<option value="{{ $model->model_key }}"
|
||||
data-input-price="{{ $model->input_price_per_million }}"
|
||||
data-output-price="{{ $model->output_price_per_million }}">
|
||||
{{ $model->model_key }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label for="input_tokens" class="block text-sm font-medium text-gray-700 mb-1">
|
||||
Input Tokens
|
||||
</label>
|
||||
<input type="number" id="input_tokens" value="1000" min="0"
|
||||
class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="output_tokens" class="block text-sm font-medium text-gray-700 mb-1">
|
||||
Output Tokens
|
||||
</label>
|
||||
<input type="number" id="output_tokens" value="500" min="0"
|
||||
class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button onclick="calculateCost()"
|
||||
class="w-full bg-blue-500 hover:bg-blue-700 text-white font-bold py-3 px-4 rounded">
|
||||
Calculate Cost
|
||||
</button>
|
||||
|
||||
<div id="result" class="hidden">
|
||||
<div class="bg-gray-50 rounded-lg p-6 space-y-3">
|
||||
<div class="flex justify-between items-center">
|
||||
<span class="text-sm text-gray-600">Model:</span>
|
||||
<span id="result_model" class="text-sm font-medium text-gray-900"></span>
|
||||
</div>
|
||||
<div class="flex justify-between items-center">
|
||||
<span class="text-sm text-gray-600">Input Tokens:</span>
|
||||
<span id="result_input_tokens" class="text-sm font-medium text-gray-900"></span>
|
||||
</div>
|
||||
<div class="flex justify-between items-center">
|
||||
<span class="text-sm text-gray-600">Output Tokens:</span>
|
||||
<span id="result_output_tokens" class="text-sm font-medium text-gray-900"></span>
|
||||
</div>
|
||||
<div class="flex justify-between items-center">
|
||||
<span class="text-sm text-gray-600">Total Tokens:</span>
|
||||
<span id="result_total_tokens" class="text-sm font-medium text-gray-900"></span>
|
||||
</div>
|
||||
<div class="border-t pt-3 mt-3">
|
||||
<div class="flex justify-between items-center">
|
||||
<span class="text-lg font-semibold text-gray-900">Total Cost:</span>
|
||||
<span id="result_cost" class="text-2xl font-bold text-green-600"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 bg-blue-50 border border-blue-200 rounded-lg p-4">
|
||||
<h4 class="font-semibold text-blue-900 mb-2">💡 Quick Reference</h4>
|
||||
<p class="text-sm text-blue-800">
|
||||
Prices are calculated per million tokens. For example, if input price is $3.00/M and you use 1,000 tokens,
|
||||
the cost would be: (1,000 / 1,000,000) × $3.00 = $0.003
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function calculateCost() {
|
||||
const modelKey = document.getElementById('calc_model').value;
|
||||
const inputTokens = parseInt(document.getElementById('input_tokens').value) || 0;
|
||||
const outputTokens = parseInt(document.getElementById('output_tokens').value) || 0;
|
||||
|
||||
if (!modelKey) {
|
||||
alert('Please select a model');
|
||||
return;
|
||||
}
|
||||
|
||||
// Get pricing from selected option
|
||||
const select = document.getElementById('calc_model');
|
||||
const option = select.options[select.selectedIndex];
|
||||
const inputPrice = parseFloat(option.dataset.inputPrice);
|
||||
const outputPrice = parseFloat(option.dataset.outputPrice);
|
||||
|
||||
// Calculate cost
|
||||
const inputCost = (inputTokens / 1000000) * inputPrice;
|
||||
const outputCost = (outputTokens / 1000000) * outputPrice;
|
||||
const totalCost = inputCost + outputCost;
|
||||
const totalTokens = inputTokens + outputTokens;
|
||||
|
||||
// Display results
|
||||
document.getElementById('result_model').textContent = modelKey;
|
||||
document.getElementById('result_input_tokens').textContent = inputTokens.toLocaleString();
|
||||
document.getElementById('result_output_tokens').textContent = outputTokens.toLocaleString();
|
||||
document.getElementById('result_total_tokens').textContent = totalTokens.toLocaleString();
|
||||
document.getElementById('result_cost').textContent = '$' + totalCost.toFixed(6);
|
||||
|
||||
document.getElementById('result').classList.remove('hidden');
|
||||
}
|
||||
|
||||
// Allow Enter key to calculate
|
||||
document.getElementById('input_tokens').addEventListener('keypress', function(e) {
|
||||
if (e.key === 'Enter') calculateCost();
|
||||
});
|
||||
document.getElementById('output_tokens').addEventListener('keypress', function(e) {
|
||||
if (e.key === 'Enter') calculateCost();
|
||||
});
|
||||
</script>
|
||||
</x-app-layout>
|
||||
71
laravel-app/resources/views/model-pricing/create.blade.php
Normal file
71
laravel-app/resources/views/model-pricing/create.blade.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<x-app-layout>
|
||||
<x-slot name="header">
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
|
||||
Add New Model Pricing
|
||||
</h2>
|
||||
</x-slot>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-2xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<form method="POST" action="{{ route('model-pricing.store') }}">
|
||||
@csrf
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="model_key" class="block text-sm font-medium text-gray-700 mb-1">
|
||||
Model Key *
|
||||
</label>
|
||||
<input type="text" name="model_key" id="model_key"
|
||||
value="{{ old('model_key') }}" required
|
||||
placeholder="e.g., gpt-4, claude-3-opus-20240229"
|
||||
class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
||||
@error('model_key')
|
||||
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="input_price_per_million" class="block text-sm font-medium text-gray-700 mb-1">
|
||||
Input Price per Million Tokens *
|
||||
</label>
|
||||
<input type="number" name="input_price_per_million" id="input_price_per_million"
|
||||
value="{{ old('input_price_per_million') }}" step="0.01" min="0" required
|
||||
placeholder="e.g., 3.00"
|
||||
class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
||||
@error('input_price_per_million')
|
||||
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
|
||||
@enderror
|
||||
<p class="mt-1 text-xs text-gray-500">Price in USD per 1 million input tokens</p>
|
||||
</div>
|
||||
|
||||
<div class="mb-6">
|
||||
<label for="output_price_per_million" class="block text-sm font-medium text-gray-700 mb-1">
|
||||
Output Price per Million Tokens *
|
||||
</label>
|
||||
<input type="number" name="output_price_per_million" id="output_price_per_million"
|
||||
value="{{ old('output_price_per_million') }}" step="0.01" min="0" required
|
||||
placeholder="e.g., 15.00"
|
||||
class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
||||
@error('output_price_per_million')
|
||||
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
|
||||
@enderror
|
||||
<p class="mt-1 text-xs text-gray-500">Price in USD per 1 million output tokens</p>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end space-x-3">
|
||||
<a href="{{ route('model-pricing.index') }}"
|
||||
class="bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded">
|
||||
Cancel
|
||||
</a>
|
||||
<button type="submit"
|
||||
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
Create Model Pricing
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</x-app-layout>
|
||||
64
laravel-app/resources/views/model-pricing/edit.blade.php
Normal file
64
laravel-app/resources/views/model-pricing/edit.blade.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<x-app-layout>
|
||||
<x-slot name="header">
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
|
||||
Edit Model Pricing: {{ $model->model_key }}
|
||||
</h2>
|
||||
</x-slot>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-2xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<form method="POST" action="{{ route('model-pricing.update', $model->model_key) }}">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Model Key</label>
|
||||
<input type="text" value="{{ $model->model_key }}" disabled
|
||||
class="w-full rounded-md border-gray-300 bg-gray-100 shadow-sm">
|
||||
<p class="mt-1 text-xs text-gray-500">Model key cannot be changed</p>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label for="input_price_per_million" class="block text-sm font-medium text-gray-700 mb-1">
|
||||
Input Price per Million Tokens *
|
||||
</label>
|
||||
<input type="number" name="input_price_per_million" id="input_price_per_million"
|
||||
value="{{ old('input_price_per_million', $model->input_price_per_million) }}"
|
||||
step="0.01" min="0" required
|
||||
class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
||||
@error('input_price_per_million')
|
||||
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="mb-6">
|
||||
<label for="output_price_per_million" class="block text-sm font-medium text-gray-700 mb-1">
|
||||
Output Price per Million Tokens *
|
||||
</label>
|
||||
<input type="number" name="output_price_per_million" id="output_price_per_million"
|
||||
value="{{ old('output_price_per_million', $model->output_price_per_million) }}"
|
||||
step="0.01" min="0" required
|
||||
class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
|
||||
@error('output_price_per_million')
|
||||
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end space-x-3">
|
||||
<a href="{{ route('model-pricing.index') }}"
|
||||
class="bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded">
|
||||
Cancel
|
||||
</a>
|
||||
<button type="submit"
|
||||
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
Update Model Pricing
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</x-app-layout>
|
||||
58
laravel-app/resources/views/model-pricing/import.blade.php
Normal file
58
laravel-app/resources/views/model-pricing/import.blade.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<x-app-layout>
|
||||
<x-slot name="header">
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
|
||||
Import Model Pricing from CSV
|
||||
</h2>
|
||||
</x-slot>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-3xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<div class="mb-6">
|
||||
<h3 class="text-lg font-semibold mb-2">CSV Format Instructions</h3>
|
||||
<p class="text-sm text-gray-600 mb-2">Your CSV file should have the following format:</p>
|
||||
<div class="bg-gray-100 p-4 rounded font-mono text-sm">
|
||||
model_key,input_price_per_million,output_price_per_million<br>
|
||||
gpt-4,30.00,60.00<br>
|
||||
gpt-3.5-turbo,0.50,1.50<br>
|
||||
claude-3-opus-20240229,15.00,75.00
|
||||
</div>
|
||||
<ul class="mt-3 text-sm text-gray-600 list-disc list-inside space-y-1">
|
||||
<li>First row must be headers (will be skipped)</li>
|
||||
<li>Existing models will be updated with new prices</li>
|
||||
<li>New models will be created</li>
|
||||
<li>Maximum file size: 2MB</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<form method="POST" action="{{ route('model-pricing.import') }}" enctype="multipart/form-data">
|
||||
@csrf
|
||||
|
||||
<div class="mb-6">
|
||||
<label for="csv_file" class="block text-sm font-medium text-gray-700 mb-1">
|
||||
Select CSV File *
|
||||
</label>
|
||||
<input type="file" name="csv_file" id="csv_file" required accept=".csv,.txt"
|
||||
class="w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-md file:border-0 file:text-sm file:font-semibold file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100">
|
||||
@error('csv_file')
|
||||
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end space-x-3">
|
||||
<a href="{{ route('model-pricing.index') }}"
|
||||
class="bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded">
|
||||
Cancel
|
||||
</a>
|
||||
<button type="submit"
|
||||
class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
|
||||
Import CSV
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</x-app-layout>
|
||||
96
laravel-app/resources/views/model-pricing/index.blade.php
Normal file
96
laravel-app/resources/views/model-pricing/index.blade.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<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">
|
||||
Model Pricing
|
||||
</h2>
|
||||
<div class="flex space-x-2">
|
||||
<a href="{{ route('model-pricing.calculator') }}"
|
||||
class="bg-purple-500 hover:bg-purple-700 text-white font-bold py-2 px-4 rounded">
|
||||
Cost Calculator
|
||||
</a>
|
||||
<a href="{{ route('model-pricing.import-form') }}"
|
||||
class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
|
||||
Import CSV
|
||||
</a>
|
||||
<a href="{{ route('model-pricing.create') }}"
|
||||
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
|
||||
Add New Model
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</x-slot>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||
@if(session('success'))
|
||||
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-4">
|
||||
{{ session('success') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6 text-gray-900">
|
||||
@if($modelPricing->count() > 0)
|
||||
<table class="min-w-full divide-y divide-gray-200">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Model
|
||||
</th>
|
||||
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Input Price
|
||||
</th>
|
||||
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Output Price
|
||||
</th>
|
||||
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Actions
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-white divide-y divide-gray-200">
|
||||
@foreach($modelPricing as $model)
|
||||
<tr>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
|
||||
{{ $model->model_key }}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-right text-blue-600 font-semibold">
|
||||
{{ $model->input_price_formatted }}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-right text-green-600 font-semibold">
|
||||
{{ $model->output_price_formatted }}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||
<a href="{{ route('model-pricing.edit', $model->model_key) }}"
|
||||
class="text-indigo-600 hover:text-indigo-900 mr-3">Edit</a>
|
||||
<form action="{{ route('model-pricing.destroy', $model->model_key) }}"
|
||||
method="POST" class="inline"
|
||||
onsubmit="return confirm('Are you sure?');">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="text-red-600 hover:text-red-900">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="mt-4">
|
||||
{{ $modelPricing->links() }}
|
||||
</div>
|
||||
@else
|
||||
<div class="text-center py-12">
|
||||
<svg class="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
<h3 class="mt-2 text-sm font-medium text-gray-900">No model pricing found</h3>
|
||||
<p class="mt-1 text-sm text-gray-500">Get started by adding a new model pricing.</p>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</x-app-layout>
|
||||
Reference in New Issue
Block a user