Skip to content

[Platform] Exposing clients to the container #1265

@Guikingone

Description

@Guikingone

Hi 👋🏻

Small suggestion for future developments regarding the Platform, for now, clients are not exposed through the container as they're built using the *PlatformFactory (example via Ollama):

<?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 Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\AI\Platform\Bridge\Ollama\Contract\OllamaContract;
use Symfony\AI\Platform\Contract;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
use Symfony\AI\Platform\Platform;
use Symfony\Component\HttpClient\EventSourceHttpClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
 * @author Christopher Hertel <mail@christopher-hertel.de>
 */
final class PlatformFactory
{
    public static function create(
        string $hostUrl = 'http://localhost:11434',
        ?HttpClientInterface $httpClient = null,
        ModelCatalogInterface $modelCatalog = new ModelCatalog(),
        ?Contract $contract = null,
        ?EventDispatcherInterface $eventDispatcher = null,
    ): Platform {
        $httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);

        return new Platform(
            [new OllamaClient($httpClient, $hostUrl)],
            [new OllamaResultConverter()],
            $modelCatalog,
            $contract ?? OllamaContract::create(),
            $eventDispatcher,
        );
    }
}

Once in the bundle, only the platform can be accessed, this approach lock the capacity to interact with the client (for decoration purposes mostly, can be useful for #943 and more) and even if the Platform is a good entry point, sometimes, we might need to interact with the client rather than the platform (which is a bit "too late" in the call chain).

Could clients be exposed in the container, maybe via a new definition during the platform building phase?

Metadata

Metadata

Assignees

No one assigned

    Labels

    PlatformIssues & PRs about the AI Platform componentRFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions