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
63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services\LLM;
|
|
|
|
use App\Services\LLM\Contracts\ProviderInterface;
|
|
use App\Services\LLM\Providers\{
|
|
OpenAIProvider,
|
|
AnthropicProvider,
|
|
MistralProvider,
|
|
GeminiProvider,
|
|
DeepSeekProvider
|
|
};
|
|
|
|
class ProviderFactory
|
|
{
|
|
/**
|
|
* Create a provider instance
|
|
*
|
|
* @param string $provider Provider name (openai, anthropic, mistral, gemini, deepseek)
|
|
* @param string $apiKey API key for the provider
|
|
* @return ProviderInterface
|
|
* @throws \InvalidArgumentException
|
|
*/
|
|
public static function create(string $provider, string $apiKey): ProviderInterface
|
|
{
|
|
return match (strtolower($provider)) {
|
|
'openai' => new OpenAIProvider($apiKey),
|
|
'anthropic' => new AnthropicProvider($apiKey),
|
|
'mistral' => new MistralProvider($apiKey),
|
|
'gemini' => new GeminiProvider($apiKey),
|
|
'deepseek' => new DeepSeekProvider($apiKey),
|
|
default => throw new \InvalidArgumentException("Unknown provider: {$provider}")
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Get list of supported providers
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function getSupportedProviders(): array
|
|
{
|
|
return [
|
|
'openai',
|
|
'anthropic',
|
|
'mistral',
|
|
'gemini',
|
|
'deepseek',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Check if a provider is supported
|
|
*
|
|
* @param string $provider
|
|
* @return bool
|
|
*/
|
|
public static function isSupported(string $provider): bool
|
|
{
|
|
return in_array(strtolower($provider), self::getSupportedProviders());
|
|
}
|
|
}
|