mirror of
https://github.com/symfony/ai-ollama-platform.git
synced 2026-03-23 23:22:07 +01:00
54 lines
1.7 KiB
PHP
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,
|
|
);
|
|
}
|
|
}
|