Skip to content

Conversation

b4s36t4
Copy link
Contributor

@b4s36t4 b4s36t4 commented Sep 4, 2025

Description

Motivation

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Testing

Screenshots (if applicable)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Related Issues

Copy link
Contributor

Code Quality bug fix new feature

Description

Summary By MatterAI MatterAI logo

🔄 What Changed

This pull request modifies src/providers/bedrock/uploadFile.ts to enable the application of inference profiles when uploading files to AWS Bedrock. The changes introduce logic to extract the foundation model from an AWS ARN, allowing users to specify models via inference profile ARNs. It also updates the getProviderConfig function to correctly identify 'titan' models when the modelSlug includes 'amazon'. The awsBedrockModel variable is now dynamically resolved if an ARN is provided.

🔍 Impact of the Change

The primary impact is enhanced flexibility for users uploading files to Bedrock, allowing them to leverage inference profiles for model selection. This improves the integration with AWS Bedrock's advanced features and simplifies model management for users who rely on ARNs. The change ensures that the correct foundation model is identified and used for file uploads, even when provided as an ARN, preventing potential errors or misconfigurations.

📁 Total Files Changed

  • src/providers/bedrock/uploadFile.ts: Modified to import getFoundationModelFromInferenceProfile, update getProviderConfig for 'amazon' models, and implement logic to resolve Bedrock model ARNs to foundation model IDs.

🧪 Test Added

N/A - No explicit tests mentioned in the PR data.

🔒Security Vulnerabilities

N/A - No new security vulnerabilities were identified in the provided changes. The ARN parsing logic should be robust to prevent unexpected behavior.

Motivation

The motivation is to fix a limitation where inference profiles could not be applied during file uploads, thereby enhancing the utility and flexibility of the Bedrock file upload functionality.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Testing
    N/A - No explicit testing details provided in the PR data.

Screenshots (if applicable)

N/A

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Tip

Quality Recommendations

  1. Add explicit error handling for the getFoundationModelFromInferenceProfile call. If the ARN resolution fails, the current code might proceed with an invalid model or throw a generic error.

  2. Consider adding logging for when an ARN is resolved to a foundation model, which can aid in debugging and understanding the flow.

  3. Implement more robust input validation for the awsBedrockModel parameter when it's an ARN to ensure it follows expected AWS ARN formats before attempting resolution.

Tanka Poem ♫

ARN now resolves,
Models flow with new found grace,
Files ascend with ease.
Bedrock's path made clearer,
Science smiles, code now complete. ✨

Sequence Diagram

sequenceDiagram
    participant Client as Client
    participant Handler as BedrockUploadFileHandler
    participant Utils as BedrockUtils
    participant AWSAPI as AWS Bedrock API
    participant S3 as AWS S3

    Client->>+Handler: POST /bedrock/uploadFile (file, providerOptions{awsBedrockModel: ARN/slug})
    Note over Handler: Extract providerOptions
    Handler->>Handler: Check awsAuthType
    alt awsAuthType === 'assumedRole'
        Handler->>Utils: providerAssumedRoleCredentials(c, providerOptions)
        Utils-->>Handler: Credentials set
    end
    Handler->>Handler: Extract awsBedrockModel (modelParam)
    alt modelParam includes 'arn:aws'
        Handler->>+Utils: getFoundationModelFromInferenceProfile(c, modelParam, providerOptions)
        Note over Utils: Resolve ARN to foundation model
        Utils->>AWSAPI: DescribeFoundationModel(ARN) OR ListFoundationModels()
        AWSAPI-->>-Utils: FoundationModelId
        Utils-->>-Handler: resolvedFoundationModelId
        Handler->>Handler: Set awsBedrockModel = resolvedFoundationModelId
    end
    Handler->>Handler: Validate awsS3Bucket and awsBedrockModel
    alt Validation Failed
        Handler-->>-Client: 400 Bad Request (Missing bucket/model)
    else Validation Success
        Handler->>+S3: AwsMultipartUploadHandler.upload(awsRegion, awsS3Bucket, awsS3ObjectKey, file)
        S3-->>-Handler: Upload Success
        Handler-->>-Client: 200 OK (Upload Status)
    end
Loading

Copy link
Contributor

@matter-code-review matter-code-review bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code correctly implements inference profile support with proper ARN handling and model extraction logic.

Comment on lines +366 to +377
if (awsBedrockModel.includes('arn:aws')) {
const foundationModel = awsBedrockModel.includes('foundation-model/')
? awsBedrockModel.split('/').pop()
: await getFoundationModelFromInferenceProfile(
c,
awsBedrockModel,
providerOptions
);
if (foundationModel) {
awsBedrockModel = foundationModel;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Bug Fix

Issue: Logic error in ARN parsing - split('/').pop() will return undefined for ARNs ending with '/' or empty segments
Fix: Add null check and fallback handling for edge cases
Impact: Prevents runtime crashes when processing malformed ARNs

Suggested change
if (awsBedrockModel.includes('arn:aws')) {
const foundationModel = awsBedrockModel.includes('foundation-model/')
? awsBedrockModel.split('/').pop()
: await getFoundationModelFromInferenceProfile(
c,
awsBedrockModel,
providerOptions
);
if (foundationModel) {
awsBedrockModel = foundationModel;
}
}
if (awsBedrockModel.includes('arn:aws')) {
const foundationModel = awsBedrockModel.includes('foundation-model/')
? awsBedrockModel.split('/').pop() || awsBedrockModel
: await getFoundationModelFromInferenceProfile(
c,
awsBedrockModel,
providerOptions
);
if (foundationModel) {
awsBedrockModel = foundationModel;
}
}

Comment on lines +339 to +343
const {
awsRegion,
awsS3Bucket,
awsBedrockModel: modelParam,
} = providerOptions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Code Refactor

Issue: Inconsistent variable naming - modelParam is used temporarily but awsBedrockModel is the actual working variable
Fix: Use more descriptive names to clarify the transformation flow
Impact: Improves code readability and reduces confusion about variable purpose

Suggested change
const {
awsRegion,
awsS3Bucket,
awsBedrockModel: modelParam,
} = providerOptions;
const {
awsRegion,
awsS3Bucket,
awsBedrockModel: originalModelParam,
} = providerOptions;

providerOptions.awsS3ObjectKey || crypto.randomUUID() + '.jsonl';

if (!awsS3Bucket || !awsBedrockModel) {
if (!awsS3Bucket || !modelParam) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Code Refactor

Issue: Variable reference should match the renamed parameter for consistency
Fix: Update validation to use the renamed parameter
Impact: Maintains consistency with variable naming convention

Suggested change
if (!awsS3Bucket || !modelParam) {
if (!awsS3Bucket || !originalModelParam) {

);
}

let awsBedrockModel = modelParam;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Code Refactor

Issue: Variable initialization should reference the renamed parameter for consistency
Fix: Update initialization to use the renamed parameter
Impact: Maintains consistency with variable naming convention

Suggested change
let awsBedrockModel = modelParam;
let awsBedrockModel = originalModelParam;

@VisargD VisargD merged commit 353024b into Portkey-AI:main Sep 16, 2025
1 check passed
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.

3 participants