Skip to content

Conversation

@junaidbhura
Copy link

Closes #180

Summary

This PR introduces the AwsBedrockProvider and its associated infrastructure. By leveraging the AWS Bedrock Converse API, this implementation provides a unified interface for multiple foundation models (Anthropic Claude, Meta Llama, Mistral, etc.) while adhering to enterprise-level security and compliance standards.

Key Implementation Details

  • Authentication: Implements AwsBedrockApiKeyRequestAuthentication. This utilizes Bedrock’s native API Key (Bearer Token) support, ensuring the SDK remains lightweight without requiring the full AWS PHP SDK or SigV4 signing.
  • Unified Converse API: Maps the library's internal structures to Bedrock's converse and converse-stream logic.
  • Multimodal Support: Full support for image and document inputs via MessagePart and File DTOs.
  • Tool Calling: Reliable mapping of FunctionDeclaration to Bedrock's toolConfig, including support for toolResult and toolUse blocks.
  • Dynamic Discovery: The AwsBedrockModelMetadataDirectory automatically infers model capabilities (Text, Image, Tools) from the AWS Control Plane.

Technical Architecture

  • Dual-Plane URLs: Correctly separates Control Plane (bedrock.region.amazonaws.com) for model listing and Runtime (bedrock-runtime.region.amazonaws.com) for inference.
  • Finish Reason Mapping: Bedrock-specific stopReason values are mapped to the library's FinishReasonEnum.

Testing & Verification

I have verified this implementation against the following scenarios using the anthropic.claude-3-5-sonnet-20241022-v2:0 model:

Test Case Status Notes
Simple Text Generation ✅ Pass System instructions and temperature respected.
Token Usage Tracking ✅ Pass Metadata correctly extracted from usage object.
Stop Sequences ✅ Pass Model successfully halts at custom stop tokens.
Multimodal (Vision) ✅ Pass Successfully described PNG/JPEG images via Base64.
Tool Calling ✅ Pass Correctly parsed toolUse arguments into FunctionCall DTOs.

Example Usage

// Set `AWS_BEDROCK_API_KEY` and `AWS_BEDROCK_REGION` environment variables 

use WordPress\AiClient\AiClient;
use WordPress\AiClient\ProviderImplementations\AwsBedrock\AwsBedrockProvider;

// The provider resolves the region via AWS_BEDROCK_REGION env variable
$result = AiClient::prompt('Summarize the benefits of using a unified AI SDK.')
    ->usingModel(AwsBedrockProvider::model('anthropic.claude-3-5-sonnet-20241022-v2:0'))
    ->usingTemperature(0.7)
    ->generateTextResult();

echo "Tokens Used: " . $result->getTokenUsage()->getTotalTokens();

@github-actions
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @junaidbhura.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: junaidbhura.


To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for AWS Bedrock (via Converse API)

1 participant