Article
Hugging Face models in Amazon Bedrock
•
14
@pagezyhf Hey Simon, wasn't sure where to post but i can confirm i was able to get myself unblocked.
Below are the steps
import boto3
import json
client = boto3.client('sagemaker-runtime', region_name='<specify region>')
endpoint_name = '<Fill me in>'
# Prepare input payload
input_payload = {
"inputs": "What is Hugging Face doing in the field of generative AI?"
}
# Convert the payload to JSON
payload_json = json.dumps(input_payload)
response = client.invoke_endpoint(
EndpointName=endpoint_name,
Body=payload_json,
ContentType='application/json'
)
result = response['Body'].read().decode('utf-8')
print(result)
raise error_class(parsed_response, operation_name)
botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the Converse operation: This action doesn't support the model that you provided. Try again with a supported text or chat model.
endpoint_arn = "arn:aws:sagemaker:<AWS::REGION>:<AWS::AccountId>:endpoint/<Endpoint_Name>"
response = bedrock_runtime.converse(
modelId=endpoint_arn,
messages=[
{
"role": "user",
"content": [
{
"text": "What is Amazon doing in the field of generative AI?",
},
]
},
],
inferenceConfig=inference_config,
additionalModelRequestFields=additional_model_fields,
)