Skip to content

i'm not able to invoke aws bedrock model locally

0

import boto3 import json

Initialize the Bedrock runtime client

brt = boto3.client(service_name='bedrock-runtime', region_name='us-east-1') # Specify your region

Define your prompt and parameters

body = json.dumps({ 'prompt': 'Human: What are the benefits of living on Mars?\nAssistant:', 'max_tokens_to_sample': 4000 })

Replace 'mistral.large.24.07' with the actual model ID

model_id = 'mistral.mistral-large-2407-v1:0'

try: # Invoke the model response = brt.invoke_model( modelId=model_id, body=body )

# Print the response
print(response['output'])

except Exception as e: print(f"An error occurred: {e}") An error occurred: An error occurred (ValidationException) when calling the InvokeModel operation: The provided model identifier is invalid.

asked 2 years ago1.1K views

3 Answers
0

Hello.

Your code tries to use "Mistral Large 2 (24.07)", but it is not available in "us-east-1".
When I checked on the management console, it was possible to enable the model in the Oregon region, so try changing to the Oregon region (us-west-2).
https://aws.amazon.com/about-aws/whats-new/2024/07/mistral-large-2-foundation-model-amazon-bedrock/?nc1=h_ls

brt = boto3.client(service_name='bedrock-runtime', region_name='us-west-2') # Specify your region

us-east-1
a

us-west-2
a

By the way, the sample code for the request for "Mistral Large 2 (24.07)" is provided in the document below.
https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-mistral-large-2407.html

EXPERT

answered 2 years ago

0

You can find a lot of Mistral on Bedrock samples in this "aws-samples" repository. https://github.com/aws-samples/mistral-on-aws/tree/main/notebooks

AWS

answered 2 years ago

-1

Based on the error message you're encountering, it appears that there are a few issues with your code and setup that need to be addressed. Let's go through them:

  1. Model ID: The error suggests that the model identifier you're using is invalid. The model ID 'mistral.mistral-large-2407-v1:0' is not a standard Amazon Bedrock model ID. Make sure you're using the correct model ID for the Bedrock service. For example, if you want to use Claude v2, the correct model ID would be 'anthropic.claude-v2'.

  2. SDK Version: Ensure that you're using the latest version of the boto3 library. Older versions may not support the Bedrock service. You can upgrade boto3 using pip:

    pip install --upgrade boto3
    
  3. Service Name: The service name 'bedrock-runtime' is correct for invoking models, but make sure your AWS credentials have the necessary permissions to access this service.

  4. Region: Verify that Bedrock is available in the 'us-east-1' region for your account and that you have enabled access to the specific model you're trying to use.

  5. Request Body: The structure of your request body looks correct for Claude models, but different models may require different input formats. Make sure you're following the specific requirements for the model you're using.

  6. Local Environment: If you're running this code locally, ensure that your AWS credentials are properly configured in your environment or AWS credentials file.

To resolve these issues:

  1. Double-check the model ID you're using and make sure it's a valid Bedrock model ID.
  2. Upgrade your boto3 library to the latest version.
  3. Verify that you have the necessary permissions to access Bedrock in your AWS account.
  4. Ensure that you've enabled access to the specific model you're trying to use in the Bedrock console.
  5. Check the Bedrock documentation for the correct input format for the specific model you're using.

If you continue to face issues after addressing these points, you may want to try using a different model or contact AWS support for further assistance.
Sources
Resolve InvokeModel API error in Amazon Bedrock | AWS re:Post
Bedrock unveiled: A Quick Lambda example | AWS re:Post

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.