Reputation: 59
I'm trying to invoke Bedrock via curl, using this command:
curl --location --request POST 'https://bedrock-runtime.us-east-1.amazonaws.com/model/cohere.command-text-v14/invoke' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Amz-Content-Sha256: op' \
--header 'X-Amz-Date: 20231104T081154Z' \
--header 'Authorization: 0-HMAC-SHA256 Credential=/20231104/us-east-1/bedrock/aws4_request, SignedHeaders=accept;content-type;host;x-amz-content-sha256;x-amz-date, Signature=' \
--data-raw '{
"inputText": "Hi",
"textGenerationConfig": {
"maxTokenCount": 4096,
"stopSequences": [],
"temperature": 0,
"topP": 0.9
}
}'
I get the below error:
Malformed input request: 3 schema violations found, please reformat your input and try again.
What is the issue?
Upvotes: 5
Views: 11037
Reputation: 9576
I had exactly this issue and finally managed to get it working by tweaking some rather cryptic parameters.
A better solution, the one I settled on and is recommended by AWS is to use the ConverseCommand
API rather than the InvokeModelCommand
API. The Converse API standardises the parameters between models.
Upvotes: 1
Reputation: 23682
You can't use Amazon Titan Model's input for the Cohere Command Model, hence the schema error.
Your request body
is for Titan. You can tell this by the inputText
field which is unique to this model's inference input. However, you've specified cohere.command-text-v14
as your model ID i.e. Cohere.
Referring to the official docs, the below will work for the Cohere model, with the equivalent parameters set from your Titan input.
curl --location --request POST 'https://bedrock-runtime.us-east-1.amazonaws.com/model/cohere.command-text-v14/invoke' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--user "$AWS_ACCESS_KEY_ID":"$AWS_SECRET_ACCESS_KEY" \
--aws-sigv4 "aws:amz:us-east-1:bedrock" \
--data-raw '{
"prompt": "Hi",
"temperature": 0,
"p": 0.9,
"max_tokens": 4096
}'
Output:
{
"generations": [
{
"finish_reason": "COMPLETE",
"id": "95e12e0f-aa3e-4812-8995-34d124b7354e",
"text": " Hello! How can I help you today?"
}
],
"id": "e7fb4f46-a046-4fd5-9bc3-340eefc9007f",
"prompt": "Hi"
}
Upvotes: 2