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:
48
laravel-app/app/Services/LLM/Contracts/ProviderInterface.php
Normal file
48
laravel-app/app/Services/LLM/Contracts/ProviderInterface.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\LLM\Contracts;
|
||||
|
||||
interface ProviderInterface
|
||||
{
|
||||
/**
|
||||
* Send a chat completion request to the provider
|
||||
*
|
||||
* @param array $messages Array of message objects with 'role' and 'content'
|
||||
* @param array $options Additional options (model, temperature, max_tokens, etc.)
|
||||
* @return array Raw provider response
|
||||
* @throws \App\Exceptions\ProviderException
|
||||
*/
|
||||
public function chatCompletion(array $messages, array $options = []): array;
|
||||
|
||||
/**
|
||||
* Normalize provider response to common format
|
||||
*
|
||||
* @param array $response Raw provider response
|
||||
* @return array Normalized response with: id, model, content, usage, finish_reason
|
||||
*/
|
||||
public function normalizeResponse(array $response): array;
|
||||
|
||||
/**
|
||||
* Calculate cost for given token usage
|
||||
*
|
||||
* @param int $promptTokens Number of prompt tokens
|
||||
* @param int $completionTokens Number of completion tokens
|
||||
* @param string $model Model name
|
||||
* @return float Total cost in USD
|
||||
*/
|
||||
public function calculateCost(int $promptTokens, int $completionTokens, string $model): float;
|
||||
|
||||
/**
|
||||
* Get supported models for this provider
|
||||
*
|
||||
* @return array List of supported model names
|
||||
*/
|
||||
public function getSupportedModels(): array;
|
||||
|
||||
/**
|
||||
* Validate API key
|
||||
*
|
||||
* @return bool True if API key is valid
|
||||
*/
|
||||
public function validateApiKey(): bool;
|
||||
}
|
||||
Reference in New Issue
Block a user