-
-
Save alexandre-bruffa/c876fe69e00b70b9830863e8c7f06eb2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import json | |
def lambda_handler(event, context): | |
bedrock = boto3.client(service_name='bedrock-runtime') | |
body = json.loads(event["body"]) | |
message = body["message"] | |
body = json.dumps({ | |
"prompt": f"\n\nHuman:{message}\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 = bedrock.invoke_model(body=body, modelId=modelId, accept=accept, contentType=contentType) | |
response_body = json.loads(response.get('body').read()) | |
answer = response_body.get('completion').strip() | |
return { | |
'statusCode': 200, | |
'body': json.dumps({"answer": answer}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment