First Commit
This commit is contained in:
Executable
+36
@@ -0,0 +1,36 @@
|
||||
<?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}"),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user