27 lines
790 B
PHP
27 lines
790 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Services\Providers\OpenAIProvider;
|
|
use App\Services\Providers\ClaudeProvider;
|
|
use App\Services\Providers\NewAPIProvider;
|
|
|
|
class AIService
|
|
{
|
|
public static function streamChat(string $providerName, string $model, array $messages, array $options, callable $onChunk): void
|
|
{
|
|
$provider = self::getProvider($providerName);
|
|
$provider::stream($model, $messages, $options, $onChunk);
|
|
}
|
|
|
|
public static function getProvider(string $name): string
|
|
{
|
|
return match ($name) {
|
|
'openai' => OpenAIProvider::class,
|
|
'claude' => ClaudeProvider::class,
|
|
'newapi' => NewAPIProvider::class,
|
|
default => throw new \RuntimeException('不支持的供应商: ' . $name)
|
|
};
|
|
}
|
|
}
|