genai-impact/ecologits

Add Amazon Bedrock provider

Closed this issue · 0 comments

Description

Add Amazon Bedrock provider.

Solution

Amazon Bedrock uses its on API and Python package.

Python package: boto3

Amazon Bedrock:

Code example:

import boto3
import json
brt = boto3.client(service_name='bedrock-runtime')

body = json.dumps({
    "prompt": "\n\nHuman: explain black holes to 8th graders\n\nAssistant:",
    "max_tokens_to_sample": 300,
    "temperature": 0.1,
    "top_p": 0.9,
})

modelId = 'anthropic.claude-v2'
accept = 'application/json'
contentType = 'application/json'

response = brt.invoke_model(body=body, modelId=modelId, accept=accept, contentType=contentType)

response_body = json.loads(response.get('body').read())

# text
print(response_body.get('completion'))