-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlatformFactory.php
More file actions
80 lines (74 loc) · 3.19 KB
/
PlatformFactory.php
File metadata and controls
80 lines (74 loc) · 3.19 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?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\Bedrock;
use AsyncAws\BedrockRuntime\BedrockRuntimeClient;
use Symfony\AI\Platform\Bridge\Anthropic\Contract as AnthropicContract;
use Symfony\AI\Platform\Bridge\Bedrock\Anthropic\ClaudeModelClient;
use Symfony\AI\Platform\Bridge\Bedrock\Anthropic\ClaudeResultConverter;
use Symfony\AI\Platform\Bridge\Bedrock\Meta\LlamaModelClient;
use Symfony\AI\Platform\Bridge\Bedrock\Meta\LlamaResultConverter;
use Symfony\AI\Platform\Bridge\Bedrock\Nova\Contract as NovaContract;
use Symfony\AI\Platform\Bridge\Bedrock\Nova\NovaModelClient;
use Symfony\AI\Platform\Bridge\Bedrock\Nova\NovaResultConverter;
use Symfony\AI\Platform\Bridge\Meta\Contract as LlamaContract;
use Symfony\AI\Platform\Contract;
use Symfony\AI\Platform\Exception\RuntimeException;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
use Symfony\AI\Platform\Platform;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @author Björn Altmann
*/
final class PlatformFactory
{
public static function create(
?BedrockRuntimeClient $bedrockRuntimeClient = null,
ModelCatalogInterface $modelCatalog = new ModelCatalog(),
?Contract $contract = null,
?EventDispatcherInterface $eventDispatcher = null,
): Platform {
if (!class_exists(BedrockRuntimeClient::class)) {
throw new RuntimeException('For using the Bedrock platform, the async-aws/bedrock-runtime package is required. Try running "composer require async-aws/bedrock-runtime".');
}
if (null === $bedrockRuntimeClient) {
$bedrockRuntimeClient = new BedrockRuntimeClient();
}
return new Platform(
[
new ClaudeModelClient($bedrockRuntimeClient),
new LlamaModelClient($bedrockRuntimeClient),
new NovaModelClient($bedrockRuntimeClient),
],
[
new ClaudeResultConverter(),
new LlamaResultConverter(),
new NovaResultConverter(),
],
$modelCatalog,
$contract ?? Contract::create(
new AnthropicContract\AssistantMessageNormalizer(),
new AnthropicContract\DocumentNormalizer(),
new AnthropicContract\DocumentUrlNormalizer(),
new AnthropicContract\ImageNormalizer(),
new AnthropicContract\ImageUrlNormalizer(),
new AnthropicContract\MessageBagNormalizer(),
new AnthropicContract\ToolCallMessageNormalizer(),
new AnthropicContract\ToolNormalizer(),
new LlamaContract\MessageBagNormalizer(),
new NovaContract\AssistantMessageNormalizer(),
new NovaContract\MessageBagNormalizer(),
new NovaContract\ToolCallMessageNormalizer(),
new NovaContract\ToolNormalizer(),
new NovaContract\UserMessageNormalizer(),
),
$eventDispatcher,
);
}
}