Skip to content

An error occurred: keys must be str, int, float, bool or None, not builtin_function_or_method

0

bedrock_runtime = boto3.client(service_name="bedrock-runtime", region_name="eu-central-1")

# Configure the model to use
model_id = "anthropic.claude-3-haiku-20240307-v1:0"
model_kwargs = {
    "max_tokens": 2048,
    "temperature": 0.1,
    "top_k": 250,
    "top_p": 1,
    "stop_sequences": ["\n\nHuman"],
    "amazon-bedrock-guardrailConfig" :  {id: "n390w1o2ad4s"}

}

asked 2 years ago658 views

4 Answers
0

Hi,

Have a look at https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-runtime/client/invoke_model.html

You have to specify the guardrail id with guardrailIdentifier param in the call of invoke() verb

response = client.invoke_model(
    body=b'bytes'|file,
    contentType='string',
    accept='string',
    modelId='string',
    trace='ENABLED'|'DISABLED',
    guardrailIdentifier='string',
    guardrailVersion='string'
)

Best,

Dider

EXPERT

answered 2 years ago

0

thanks but i need the langchain equivalent

answered 2 years ago

0

Not sure what do you mean by the sane as langchain, but you can check the new API https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html#conversation-inference-examples

AWS

answered 2 years ago

0

In Python, the keys of dictionaries are variable references unless explicitly quoted...

So I believe this error is coming from your:

{id: "n390w1o2ad4s"}

...Which should instead be:

{"id": "n390w1o2ad4s"}

(id() is a built-in function in Python, otherwise you'd get a reference error)

However, I'm not sure this is actually the correct parameter to specify a guardrail. The parameter is guardrailIdentifier for boto3 as noted in the other answer, and for LangChain you might want to check the docs here?

AWS
EXPERT

answered 2 years 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.