-
-
Notifications
You must be signed in to change notification settings - Fork 148
[AI Bundle][Platform] Allow configure Bedrock platform via bundle config #1206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
uerka
wants to merge
17
commits into
symfony:main
Choose a base branch
from
dekkode:feat/bedrock-platform-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+254
−1
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7b03968
feat(platform): allow configure bedrock platform with support of mult…
uerka 1107cf1
fix(nova): avoid populate model name to message payload
uerka 6f955a9
chore(bedrock): throw exception if client is missing
uerka 2bd33fb
chore(bedrock): ensure bedrock platform can be initiated via bundle c…
uerka 754aae8
chore(bedrock): cover model clients with tests
uerka da78df0
chore(bedrock): allow pass null as bedrock client
uerka dad6939
chore(bedrock): rollback unnecessary change
uerka bb3258b
fix(demo): fixing typo in package name
uerka 6788d75
chore(cs): strict comparison to null for passed bedrock runtime client
uerka 9031970
chore(cs): assertEquals -> assertSame
uerka 44bc2e2
chore(cs): missing quote
uerka 14bdc91
fix(bundle): check for bedrock platform package only in case at least…
uerka 4a597bd
chore(cs): rollback assertEquals -> assertSame where was not intended
uerka 232f3f9
chore(bedrock): rename ai.platform.bedrock_{name} to ai.platform.bedr…
uerka aa46462
chore(docs): change to ai.platform.bedrock.{name} for agent definition
uerka 6c8dec9
chore(cs): fixing cs
uerka f219864
chore(cs): fixing cs
uerka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190 changes: 190 additions & 0 deletions
190
src/platform/src/Bridge/Bedrock/Tests/Nova/NovaModelClientTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Symfony package. | ||
| * | ||
| * (c) Fabien Potencier <[email protected]> | ||
| * | ||
| * 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\Tests\Nova; | ||
|
|
||
| use AsyncAws\BedrockRuntime\BedrockRuntimeClient; | ||
| use AsyncAws\BedrockRuntime\Input\InvokeModelRequest; | ||
| use AsyncAws\BedrockRuntime\Result\InvokeModelResponse; | ||
| use AsyncAws\Core\Configuration; | ||
| use PHPUnit\Framework\MockObject\MockObject; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Symfony\AI\Platform\Bridge\Bedrock\Nova\Nova; | ||
| use Symfony\AI\Platform\Bridge\Bedrock\Nova\NovaModelClient; | ||
| use Symfony\AI\Platform\Bridge\Bedrock\RawBedrockResult; | ||
|
|
||
| final class NovaModelClientTest extends TestCase | ||
| { | ||
| private MockObject&BedrockRuntimeClient $bedrockClient; | ||
| private NovaModelClient $modelClient; | ||
| private Nova $model; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| $this->model = new Nova('nova-pro'); | ||
| $this->bedrockClient = $this->getMockBuilder(BedrockRuntimeClient::class) | ||
| ->setConstructorArgs([ | ||
| Configuration::create([Configuration::OPTION_REGION => Configuration::DEFAULT_REGION]), | ||
| ]) | ||
| ->onlyMethods(['invokeModel']) | ||
| ->getMock(); | ||
| } | ||
|
|
||
| public function testPassesModelId() | ||
| { | ||
| $this->bedrockClient->expects($this->once()) | ||
| ->method('invokeModel') | ||
| ->with($this->callback(function ($arg) { | ||
| $this->assertInstanceOf(InvokeModelRequest::class, $arg); | ||
| $this->assertSame('us.amazon.nova-pro-v1:0', $arg->getModelId()); | ||
| $this->assertSame('application/json', $arg->getContentType()); | ||
| $this->assertTrue(json_validate($arg->getBody())); | ||
|
|
||
| return true; | ||
| })) | ||
| ->willReturn($this->createMock(InvokeModelResponse::class)); | ||
|
|
||
| $this->modelClient = new NovaModelClient($this->bedrockClient); | ||
|
|
||
| $response = $this->modelClient->request($this->model, ['message' => 'test']); | ||
| $this->assertInstanceOf(RawBedrockResult::class, $response); | ||
| } | ||
|
|
||
| public function testUnsetsModelName() | ||
| { | ||
| $this->bedrockClient->expects($this->once()) | ||
| ->method('invokeModel') | ||
| ->with($this->callback(function ($arg) { | ||
| $this->assertInstanceOf(InvokeModelRequest::class, $arg); | ||
| $this->assertSame('application/json', $arg->getContentType()); | ||
| $this->assertTrue(json_validate($arg->getBody())); | ||
|
|
||
| $body = json_decode($arg->getBody(), true); | ||
| $this->assertArrayNotHasKey('model', $body); | ||
|
|
||
| return true; | ||
| })) | ||
| ->willReturn($this->createMock(InvokeModelResponse::class)); | ||
|
|
||
| $this->modelClient = new NovaModelClient($this->bedrockClient); | ||
|
|
||
| $response = $this->modelClient->request($this->model, ['message' => 'test', 'model' => 'nova-pro']); | ||
| $this->assertInstanceOf(RawBedrockResult::class, $response); | ||
| } | ||
|
|
||
| public function testSetsToolOptionsIfToolsEnabled() | ||
| { | ||
| $this->bedrockClient->expects($this->once()) | ||
| ->method('invokeModel') | ||
| ->with($this->callback(function ($arg) { | ||
| $this->assertInstanceOf(InvokeModelRequest::class, $arg); | ||
| $this->assertSame('application/json', $arg->getContentType()); | ||
| $this->assertTrue(json_validate($arg->getBody())); | ||
|
|
||
| $body = json_decode($arg->getBody(), true); | ||
| $this->assertSame(['tools' => ['Tool']], $body['toolConfig']); | ||
|
|
||
| return true; | ||
| })) | ||
| ->willReturn($this->createMock(InvokeModelResponse::class)); | ||
|
|
||
| $this->modelClient = new NovaModelClient($this->bedrockClient); | ||
|
|
||
| $options = [ | ||
| 'tools' => ['Tool'], | ||
| ]; | ||
|
|
||
| $response = $this->modelClient->request($this->model, ['message' => 'test'], $options); | ||
| $this->assertInstanceOf(RawBedrockResult::class, $response); | ||
| } | ||
|
|
||
| public function testPassesTemperature() | ||
| { | ||
| $this->bedrockClient->expects($this->once()) | ||
| ->method('invokeModel') | ||
| ->with($this->callback(function ($arg) { | ||
| $this->assertInstanceOf(InvokeModelRequest::class, $arg); | ||
| $this->assertSame('application/json', $arg->getContentType()); | ||
| $this->assertTrue(json_validate($arg->getBody())); | ||
|
|
||
| $body = json_decode($arg->getBody(), true); | ||
| $this->assertArrayHasKey('inferenceConfig', $body); | ||
| $this->assertSame(['temperature' => 0.35], $body['inferenceConfig']); | ||
|
|
||
| return true; | ||
| })) | ||
| ->willReturn($this->createMock(InvokeModelResponse::class)); | ||
|
|
||
| $this->modelClient = new NovaModelClient($this->bedrockClient); | ||
|
|
||
| $options = [ | ||
| 'temperature' => 0.35, | ||
| ]; | ||
|
|
||
| $response = $this->modelClient->request($this->model, ['message' => 'test'], $options); | ||
| $this->assertInstanceOf(RawBedrockResult::class, $response); | ||
| } | ||
|
|
||
| public function testPassesMaxTokens() | ||
| { | ||
| $this->bedrockClient->expects($this->once()) | ||
| ->method('invokeModel') | ||
| ->with($this->callback(function ($arg) { | ||
| $this->assertInstanceOf(InvokeModelRequest::class, $arg); | ||
| $this->assertSame('application/json', $arg->getContentType()); | ||
| $this->assertTrue(json_validate($arg->getBody())); | ||
|
|
||
| $body = json_decode($arg->getBody(), true); | ||
| $this->assertArrayHasKey('inferenceConfig', $body); | ||
| $this->assertSame(['maxTokens' => 1000], $body['inferenceConfig']); | ||
|
|
||
| return true; | ||
| })) | ||
| ->willReturn($this->createMock(InvokeModelResponse::class)); | ||
|
|
||
| $this->modelClient = new NovaModelClient($this->bedrockClient); | ||
|
|
||
| $options = [ | ||
| 'max_tokens' => 1000, | ||
| ]; | ||
|
|
||
| $response = $this->modelClient->request($this->model, ['message' => 'test'], $options); | ||
| $this->assertInstanceOf(RawBedrockResult::class, $response); | ||
| } | ||
|
|
||
| public function testPassesBothTemperatureAndMaxTokens() | ||
| { | ||
| $this->bedrockClient->expects($this->once()) | ||
| ->method('invokeModel') | ||
| ->with($this->callback(function ($arg) { | ||
| $this->assertInstanceOf(InvokeModelRequest::class, $arg); | ||
| $this->assertSame('application/json', $arg->getContentType()); | ||
| $this->assertTrue(json_validate($arg->getBody())); | ||
|
|
||
| $body = json_decode($arg->getBody(), true); | ||
| $this->assertArrayHasKey('inferenceConfig', $body); | ||
| $this->assertSame(['temperature' => 0.35, 'maxTokens' => 1000], $body['inferenceConfig']); | ||
|
|
||
| return true; | ||
| })) | ||
| ->willReturn($this->createMock(InvokeModelResponse::class)); | ||
|
|
||
| $this->modelClient = new NovaModelClient($this->bedrockClient); | ||
|
|
||
| $options = [ | ||
| 'max_tokens' => 1000, | ||
| 'temperature' => 0.35, | ||
| ]; | ||
|
|
||
| $response = $this->modelClient->request($this->model, ['message' => 'test'], $options); | ||
| $this->assertInstanceOf(RawBedrockResult::class, $response); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.