|
14 | 14 | use Symfony\AI\Platform\Bridge\Perplexity\Contract\PerplexityContract; |
15 | 15 | use Symfony\AI\Platform\Contract; |
16 | 16 | use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface; |
| 17 | +use Symfony\AI\Platform\ModelRouter\CatalogBasedModelRouter; |
| 18 | +use Symfony\AI\Platform\ModelRouterInterface; |
17 | 19 | use Symfony\AI\Platform\Platform; |
| 20 | +use Symfony\AI\Platform\Provider; |
| 21 | +use Symfony\AI\Platform\ProviderInterface; |
18 | 22 | use Symfony\Component\HttpClient\EventSourceHttpClient; |
19 | 23 | use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; |
20 | 24 | use Symfony\Contracts\HttpClient\HttpClientInterface; |
21 | 25 |
|
22 | 26 | /** |
23 | 27 | * @author Mathieu Santostefano <[email protected]> |
24 | 28 | */ |
25 | | -final class PlatformFactory |
| 29 | +final class Factory |
26 | 30 | { |
27 | | - public static function create( |
| 31 | + /** |
| 32 | + * @param non-empty-string $name |
| 33 | + */ |
| 34 | + public static function createProvider( |
28 | 35 | #[\SensitiveParameter] string $apiKey, |
29 | 36 | ?HttpClientInterface $httpClient = null, |
30 | 37 | ModelCatalogInterface $modelCatalog = new ModelCatalog(), |
31 | 38 | ?Contract $contract = null, |
32 | 39 | ?EventDispatcherInterface $eventDispatcher = null, |
33 | | - ): Platform { |
| 40 | + string $name = 'perplexity', |
| 41 | + ): ProviderInterface { |
34 | 42 | $httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient); |
35 | 43 |
|
36 | | - return new Platform( |
| 44 | + return new Provider( |
| 45 | + $name, |
37 | 46 | [new ModelClient($httpClient, $apiKey)], |
38 | 47 | [new ResultConverter()], |
39 | 48 | $modelCatalog, |
40 | 49 | $contract ?? PerplexityContract::create(), |
41 | 50 | $eventDispatcher, |
42 | 51 | ); |
43 | 52 | } |
| 53 | + |
| 54 | + /** |
| 55 | + * @param non-empty-string $name |
| 56 | + */ |
| 57 | + public static function createPlatform( |
| 58 | + #[\SensitiveParameter] string $apiKey, |
| 59 | + ?HttpClientInterface $httpClient = null, |
| 60 | + ModelCatalogInterface $modelCatalog = new ModelCatalog(), |
| 61 | + ?Contract $contract = null, |
| 62 | + ?EventDispatcherInterface $eventDispatcher = null, |
| 63 | + string $name = 'perplexity', |
| 64 | + ?ModelRouterInterface $modelRouter = null, |
| 65 | + ): Platform { |
| 66 | + return new Platform( |
| 67 | + [self::createProvider($apiKey, $httpClient, $modelCatalog, $contract, $eventDispatcher, $name)], |
| 68 | + $modelRouter ?? new CatalogBasedModelRouter(), |
| 69 | + $eventDispatcher, |
| 70 | + ); |
| 71 | + } |
44 | 72 | } |
0 commit comments