Skip to content

Commit 30c655a

Browse files
committed
minor #668 [Platform][Anthropic] Modify Claude constructor max_tokens handling (OskarStark)
This PR was merged into the main branch. Discussion ---------- [Platform][Anthropic] Modify Claude constructor `max_tokens` handling | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | no | Issues | Follows #667 | License | MIT Commits ------- c7f6fcf [Platform] Fix Claude constructor max_tokens logic
2 parents dba7bb0 + c7f6fcf commit 30c655a

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/platform/src/Bridge/Anthropic/Claude.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Claude extends Model
3434
/**
3535
* @param array<string, mixed> $options The default options for the model usage
3636
*/
37-
public function __construct(string $name, array $options = ['max_tokens' => 1000])
37+
public function __construct(string $name, array $options = [])
3838
{
3939
$capabilities = [
4040
Capability::INPUT_MESSAGES,
@@ -44,6 +44,10 @@ public function __construct(string $name, array $options = ['max_tokens' => 1000
4444
Capability::TOOL_CALLING,
4545
];
4646

47+
if (!isset($options['max_tokens'])) {
48+
$options['max_tokens'] = 1000;
49+
}
50+
4751
parent::__construct($name, $capabilities, $options);
4852
}
4953
}
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 Symfony\AI\Platform\Tests\Bridge\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)