Files
archived-ai-ollama-platform/PlatformFactory.php
2026-03-17 10:11:34 +01:00

54 lines
1.7 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\AI\Platform\Bridge\Ollama;
use Symfony\AI\Platform\Bridge\Ollama\Contract\OllamaContract;
use Symfony\AI\Platform\Contract;
use Symfony\AI\Platform\Platform;
use Symfony\Component\HttpClient\EventSourceHttpClient;
use Symfony\Component\HttpClient\ScopingHttpClient;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* @author Christopher Hertel <mail@christopher-hertel.de>
*/
final class PlatformFactory
{
public static function create(
?string $endpoint = null,
#[\SensitiveParameter] ?string $apiKey = null,
?HttpClientInterface $httpClient = null,
?Contract $contract = null,
?EventDispatcherInterface $eventDispatcher = null,
): Platform {
$httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
if (null !== $endpoint) {
$defaultOptions = [];
if (null !== $apiKey) {
$defaultOptions['auth_bearer'] = $apiKey;
}
$httpClient = ScopingHttpClient::forBaseUri($httpClient, $endpoint, $defaultOptions);
}
return new Platform(
[new OllamaClient($httpClient)],
[new OllamaResultConverter()],
new ModelCatalog($httpClient),
$contract ?? OllamaContract::create(),
$eventDispatcher,
);
}
}