Bedrock error when calling

0
  bedrock_client = boto3.client(
    service_name="bedrock-runtime",
    region_name="us-east-1"
    )
 llm = Bedrock(
        model_id=modelID,
        client=bedrock_client,
        model_kwargs={"max_tokens_to_sample":300,"temperature":.5,"top_k":250,"top_p":0.999,"anthropic_version":"bedrock-2023-05-31"},
    )

It throws error as ValueError: Error raised by bedrock service: An error occurred (ValidationException) when calling the InvokeModel operation: Malformed input request: 5 schema violations found, please reformat your input and try again. Please give me some suggestions for solving this error.

Dipika
已提問 5 個月前檢視次數 1665 次
1 個回答
1

@Dipika Thanks for reaching out.

As the error message says, there has been a validation error for the input prompt. Not all FMs have the same input prompt format. For instance: The input prompt format for Claude is as below.

# Claude requires you to enclose the prompt as follows:
            enclosed_prompt = "Human: " + prompt + "\n\nAssistant:"

            body = {
                "prompt": enclosed_prompt,
                "max_tokens_to_sample": 200,
                "temperature": 0.5,
                "stop_sequences": ["\n\nHuman:"],
            }

Please find the detailed examples here for different programming languages:

https://docs.aws.amazon.com/code-library/latest/ug/bedrock-runtime_code_examples_actions.html

Thanks, Arjun

AWS
已回答 5 個月前
profile picture
專家
已審閱 2 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南