aws-samples / amazon-bedrock-workshop

This is a workshop designed for Amazon Bedrock a foundational model service.
https://catalog.us-east-1.prod.workshops.aws/workshops/a4bdb007-5600-4368-81c5-ff5b4154f518/en-US/20-intro
MIT No Attribution
1.39k stars 591 forks source link

Error in invoke model #58

Closed rahulaga closed 11 months ago

rahulaga commented 11 months ago

I'm trying the intro on my local. The list_foundation_models() works fine so my setup should be good.

However in invoke_model it fails. Any suggestions?

2023-09-29 09:01:11,154 botocore.parsers [DEBUG] Response headers: {'Date': 'Fri, 29 Sep 2023 16:01:11 GMT', 'Content-Type': 'application/json', 'Content-Length': '71', 'Connection': 'keep-alive', 'x-amzn-RequestId': 'd6c4953c-76db-4eb4-bb6c-cf162fa9320d', 'x-amzn-ErrorType': 'ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock.build/'}
2023-09-29 09:01:11,155 botocore.parsers [DEBUG] Response body:
b'{"message":"The requested operation is not recognized by the service."}'
pkumar8789 commented 11 months ago

I am using the bedrock.invoke_model( body=body, modelId=modelId, accept=accept, contentType=contentType ) and getting the above message. boto3 latest doc does suggest that the method is available in bedrock_runtime but this service is not available in the boto3-1.28.21

alkayahan commented 11 months ago

Hi,

In bedrock-boto3-setup.ipynb, in cell 6, try to set the endpoint url as below. Make sure you change the yourregion word to whichever region you are running in. e.g. us-east-1.

endpoint_url=os.environ.get("BEDROCK_ENDPOINT_URL", "https://invoke-bedrock.yourregion.amazonaws.com/")

pkumar8789 commented 11 months ago

Hi,

In bedrock-boto3-setup.ipynb, in cell 6, try to set the endpoint url as below. Make sure you change the yourregion word to whichever region you are running in. e.g. us-east-1.

endpoint_url=os.environ.get("BEDROCK_ENDPOINT_URL", "https://invoke-bedrock.yourregion.amazonaws.com/")

My endpoint seems to be fine and takes region into account: Output: Using region: us-east-1 boto3 Bedrock client successfully created! bedrock(https://bedrock.us-east-1.amazonaws.com/)

alkayahan commented 11 months ago

I don't think so. The response you get is returned when you don't change the current code in the cell of the notebook where BEDROCK_ENDPOINT_URL is passed as None. Your endpoint should look like invoke-bedrock.us-east-1.amazon.aws.com or bedrock-runtime.us-east-1.amazon.aws.com and not bedrock.us-east-1.amazon.aws.com.

alkayahan commented 11 months ago

I also see a recent merge on changing the endpoint URL handling (looks like bedrock-runtime is being produced as default instead of bedrock), you may consider to git pull for the recent changes and see whether that helps.

rahulaga commented 11 months ago

@alkayahan not sure where you got those URLs from? This is the only URL: https://catalog.us-east-1.prod.workshops.aws/workshops/a4bdb007-5600-4368-81c5-ff5b4154f518/en-US/20-intro/21-environmentsetup

pkumar8789 commented 11 months ago

Works fine with latest git pull and below versions: "boto3>=1.28.57" "awscli>=1.29.57" "botocore>=1.31.57"

%pip install --quiet langchain==0.0.305