-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlatformFactory.php
More file actions
60 lines (54 loc) · 2.05 KB
/
PlatformFactory.php
File metadata and controls
60 lines (54 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?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\OpenAi;
use Symfony\AI\Platform\Bridge\OpenAi\Contract\OpenAiContract;
use Symfony\AI\Platform\Contract;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
use Symfony\AI\Platform\Platform;
use Symfony\Component\HttpClient\EventSourceHttpClient;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* @author Christopher Hertel <mail@christopher-hertel.de>
*/
final class PlatformFactory
{
public const REGION_EU = 'EU';
public const REGION_US = 'US';
public static function create(
#[\SensitiveParameter] string $apiKey,
?HttpClientInterface $httpClient = null,
ModelCatalogInterface $modelCatalog = new ModelCatalog(),
?Contract $contract = null,
?string $region = null,
?EventDispatcherInterface $eventDispatcher = null,
): Platform {
$httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
return new Platform(
[
new Gpt\ModelClient($httpClient, $apiKey, $region),
new Embeddings\ModelClient($httpClient, $apiKey, $region),
new DallE\ModelClient($httpClient, $apiKey, $region),
new TextToSpeech\ModelClient($httpClient, $apiKey, $region),
new Whisper\ModelClient($httpClient, $apiKey, $region),
],
[
new Gpt\ResultConverter(),
new Embeddings\ResultConverter(),
new DallE\ResultConverter(),
new TextToSpeech\ResultConverter(),
new Whisper\ResultConverter(),
],
$modelCatalog,
$contract ?? OpenAiContract::create(),
$eventDispatcher,
);
}
}