Error InvokeModel
Closed this issue · 1 comments
Hausdorff94 commented
I run the cell in Notebook intro_to_bedrock.ipynb
# first fetch possible styles and give options to customer
prompt = """
Human: list different style options for:
""" + customer_input + """
Assistant:"""
body = json.dumps({"prompt": prompt, "max_tokens_to_sample": 500})
modelId = "amazon.titan-text-express-v1" # change this to use a different version from the model provider
accept = "application/json"
contentType = "application/json"
claudeResponse = ""
response = bedrock_runtime.invoke_model(
body=body, modelId=modelId, accept=accept, contentType=contentType
)
response_body = json.loads(response.get("body").read())
styles_response = response_body.get("completion")
print(styles_response)
And I got the following error:
ValidationException Traceback (most recent call last)
Cell In[5], line 14
11 contentType = "application/json"
12 claudeResponse = ""
---> 14 response = bedrock_runtime.invoke_model(
15 body=body, modelId=modelId, accept=accept, contentType=contentType
16 )
17 response_body = json.loads(response.get("body").read())
18 styles_response = response_body.get("completion")
File /opt/conda/lib/python3.10/site-packages/botocore/client.py:553, in ClientCreator._create_api_method.<locals>._api_call(self, *args, **kwargs)
549 raise TypeError(
550 f"{py_operation_name}() only accepts keyword arguments."
551 )
552 # The "self" in this scope is referring to the BaseClient.
--> 553 return self._make_api_call(operation_name, kwargs)
File /opt/conda/lib/python3.10/site-packages/botocore/client.py:1009, in BaseClient._make_api_call(self, operation_name, api_params)
1005 error_code = error_info.get("QueryErrorCode") or error_info.get(
1006 "Code"
1007 )
1008 error_class = self.exceptions.from_code(error_code)
-> 1009 raise error_class(parsed_response, operation_name)
1010 else:
1011 return parsed_response
ValidationException: An error occurred (ValidationException) when calling the InvokeModel operation: Malformed input request: 3 schema violations found, please reformat your input and try again.
Any idea how to solve it?
Hausdorff94 commented
Update: I was using wrong payload for Titan model