amazon-bedrock-workshop icon indicating copy to clipboard operation
amazon-bedrock-workshop copied to clipboard

invoke model errors / 00_generate_w_bedrock.ipynb

Open gcube9 opened this issue 2 years ago • 2 comments


AttributeError Traceback (most recent call last) Cell In[21], line 8 4 outputText = "\n" 6 try: ----> 8 response = boto3_bedrock.invoke_model(body=body, modelId=modelId, accept=accept, contentType=contentType) 9 response_body = json.loads(response.get("body").read()) 11 outputText = response_body.get('results')[0].get('outputText')

File /opt/conda/lib/python3.10/site-packages/botocore/client.py:888, in BaseClient.getattr(self, item) 885 if event_response is not None: 886 return event_response --> 888 raise AttributeError( 889 f"'{self.class.name}' object has no attribute '{item}'" 890 )

AttributeError: 'Bedrock' object has no attribute 'invoke_model'

gcube9 avatar Oct 25 '23 03:10 gcube9

are you running the workshop in SageMaker studio? if so, you need to add the bedrock permissions to the SageMaker execution role. If you are running in your own laptop, ensure your user/role has the right permissions by updating the code in the first cell.

govin-pal avatar Dec 20 '23 19:12 govin-pal

Make sure to set runtime= True in the setup script and try to run the commands which involve Invoke operations

boto3_bedrock = bedrock.get_bedrock_client( assumed_role=os.environ.get("BEDROCK_ASSUME_ROLE", None), region=os.environ.get("AWS_DEFAULT_REGION", None), runtime=False )

adnanrizve avatar Mar 04 '24 21:03 adnanrizve

Closing this; please refer to the latest bedrock workshop update and reopen if still relevant

w601sxs avatar Apr 09 '24 19:04 w601sxs