Encountering 'ResourceNotFoundException' when using Amazon Bedrock models

0

I'm trying to use the foundational models in Amazon Bedrock to build a simple chatbot using Python. I create Boto3 client and set the model ID, accept and content types as:

bedrock = boto3.client(
  service_name='bedrock-runtime', 
  region_name="us-east-1"
)

modelId = 'cohere.command-text-v14'
accept = 'application/json'
contentType = 'application/json'
body = json.dumps({
    "prompt": "Hello World",
    "temperature": 0.75,
    "p": 0.01,
    "k": 0,
})

I then try to generate text by using invoke_model:

response = bedrock.invoke_model(body=body, modelId=modelId, accept=accept, contentType=contentType)
response_body = json.loads(response.get('body').read())
print(response_body['generations'][0]['text'])

I get the following error:

---------------------------------------------------------------------------
ResourceNotFoundException                 Traceback (most recent call last)

      3 contentType = 'application/json'
      4 
----> 5 response = bedrock.invoke_model(body=body, modelId=modelId, accept=accept, contentType=contentType)
      6 
      7 response_body = json.loads(response.get('body').read())

~/Library/Python/3.8/lib/python/site-packages/botocore/client.py in _api_call(self, *args, **kwargs)
    551                 )
    552             # The "self" in this scope is referring to the BaseClient.
--> 553             return self._make_api_call(operation_name, kwargs)
    554 
    555         _api_call.__name__ = str(py_operation_name)

~/Library/Python/3.8/lib/python/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
   1007             )
   1008             error_class = self.exceptions.from_code(error_code)
-> 1009             raise error_class(parsed_response, operation_name)
   1010         else:
   1011             return parsed_response

ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the InvokeModel operation: Could not resolve the foundation model from the provided model identifier.

rrahul
asked 6 months ago878 views
1 Answer
0
  1. Please check if you add model access https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html#add-model-access
  2. Can you see the cohere.command-text-v14 model in the list_foundation_models() method, which will tell us all the models available for us to use boto3_bedrock.list_foundation_models() ​
Orgad
answered 6 months 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.

Guidelines for Answering Questions