37 lines
1.0 KiB
PHP
Executable File
37 lines
1.0 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Ai;
|
|
|
|
use App\Models\AiProvider;
|
|
use InvalidArgumentException;
|
|
|
|
class AiServiceFactory
|
|
{
|
|
/**
|
|
* Create an AI service instance based on the provider.
|
|
*
|
|
* @param AiProvider|string $provider
|
|
* @return AiServiceInterface
|
|
*/
|
|
public static function make(AiProvider|string $provider): AiServiceInterface
|
|
{
|
|
if (is_string($provider)) {
|
|
$provider = AiProvider::withTrashed()->where('slug', $provider)
|
|
->firstOrFail();
|
|
}
|
|
|
|
if (!$provider->is_active) {
|
|
throw new InvalidArgumentException('AI provider is not active.');
|
|
}
|
|
|
|
return match ($provider->slug) {
|
|
'openrouter', 'openrouter-test' => new OpenRouterService($provider),
|
|
'stepfun' => new StepFunService($provider),
|
|
'llamacpp' => new LlamaCppService($provider),
|
|
default => throw new InvalidArgumentException("Unsupported AI provider: {$provider->slug}"),
|
|
};
|
|
}
|
|
}
|