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
preguntada hace 5 meses1669 visualizaciones
1 Respuesta
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
respondido hace 5 meses
profile picture
EXPERTO
revisado hace 2 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas