Skip to content

Commit 3ae4ae1

Browse files
committed
[Platform][Bedrock] Use dedicated model class
1 parent a4ab920 commit 3ae4ae1

File tree

5 files changed

+99
-3
lines changed

5 files changed

+99
-3
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\AI\Platform\Bridge\Bedrock\Anthropic;
13+
14+
use Symfony\AI\Platform\Capability;
15+
use Symfony\AI\Platform\Model;
16+
17+
/**
18+
* @author Christopher Hertel <[email protected]>
19+
*/
20+
class Claude extends Model
21+
{
22+
public const HAIKU_3 = 'claude-3-haiku-20240307';
23+
public const HAIKU_35 = 'claude-3-5-haiku-latest';
24+
public const SONNET_3 = 'claude-3-sonnet-20240229';
25+
public const SONNET_35 = 'claude-3-5-sonnet-latest';
26+
public const SONNET_37 = 'claude-3-7-sonnet-latest';
27+
public const SONNET_4 = 'claude-sonnet-4-20250514';
28+
public const SONNET_4_0 = 'claude-sonnet-4-0';
29+
public const OPUS_3 = 'claude-3-opus-20240229';
30+
public const OPUS_4 = 'claude-opus-4-20250514';
31+
public const OPUS_4_0 = 'claude-opus-4-0';
32+
public const OPUS_4_1 = 'claude-opus-4-1';
33+
34+
/**
35+
* @param array<string, mixed> $options The default options for the model usage
36+
*/
37+
public function __construct(string $name, array $options = [])
38+
{
39+
$capabilities = [
40+
Capability::INPUT_MESSAGES,
41+
Capability::INPUT_IMAGE,
42+
Capability::OUTPUT_TEXT,
43+
Capability::OUTPUT_STREAMING,
44+
Capability::TOOL_CALLING,
45+
];
46+
47+
if (!isset($options['max_tokens'])) {
48+
$options['max_tokens'] = 1000;
49+
}
50+
51+
parent::__construct($name, $capabilities, $options);
52+
}
53+
}

src/Bridge/Bedrock/Anthropic/ClaudeModelClient.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use AsyncAws\BedrockRuntime\BedrockRuntimeClient;
1515
use AsyncAws\BedrockRuntime\Input\InvokeModelRequest;
1616
use AsyncAws\BedrockRuntime\Result\InvokeModelResponse;
17-
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
1817
use Symfony\AI\Platform\Bridge\Bedrock\RawBedrockResult;
1918
use Symfony\AI\Platform\Exception\RuntimeException;
2019
use Symfony\AI\Platform\Model;

src/Bridge/Bedrock/Anthropic/ClaudeResultConverter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\AI\Platform\Bridge\Bedrock\Anthropic;
1313

14-
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
1514
use Symfony\AI\Platform\Bridge\Bedrock\RawBedrockResult;
1615
use Symfony\AI\Platform\Exception\RuntimeException;
1716
use Symfony\AI\Platform\Model;

tests/Bridge/Bedrock/Anthropic/ClaudeResultConverterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use AsyncAws\Core\Test\ResultMockFactory;
1616
use PHPUnit\Framework\Attributes\TestDox;
1717
use PHPUnit\Framework\TestCase;
18-
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
18+
use Symfony\AI\Platform\Bridge\Bedrock\Anthropic\Claude;
1919
use Symfony\AI\Platform\Bridge\Bedrock\Anthropic\ClaudeResultConverter;
2020
use Symfony\AI\Platform\Bridge\Bedrock\RawBedrockResult;
2121
use Symfony\AI\Platform\Exception\RuntimeException;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Bridge\Bedrock\Anthropic;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
16+
17+
/**
18+
* @author Oskar Stark <[email protected]>
19+
*/
20+
final class ClaudeTest extends TestCase
21+
{
22+
public function testItCreatesClaudeWithDefaultSettings()
23+
{
24+
$claude = new Claude(Claude::SONNET_35);
25+
26+
$this->assertSame(Claude::SONNET_35, $claude->getName());
27+
$this->assertSame(['max_tokens' => 1000], $claude->getOptions());
28+
}
29+
30+
public function testItCreatesClaudeWithCustomSettingsIncludingMaxTokens()
31+
{
32+
$claude = new Claude(Claude::SONNET_35, ['temperature' => 0.5, 'max_tokens' => 2000]);
33+
34+
$this->assertSame(Claude::SONNET_35, $claude->getName());
35+
$this->assertSame(['temperature' => 0.5, 'max_tokens' => 2000], $claude->getOptions());
36+
}
37+
38+
public function testItCreatesClaudeWithCustomSettingsWithoutMaxTokens()
39+
{
40+
$claude = new Claude(Claude::SONNET_35, ['temperature' => 0.5]);
41+
42+
$this->assertSame(Claude::SONNET_35, $claude->getName());
43+
$this->assertSame(['temperature' => 0.5, 'max_tokens' => 1000], $claude->getOptions());
44+
}
45+
}

0 commit comments

Comments
 (0)