Last active
January 5, 2024 07:53
-
-
Save aashishrbhandari/4863725a01fe98856428554878a691a9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
""" | |
Overview: | |
Make an API call to bedrock to get Prompt Results | |
Note: It uses IAM Role for making API call to AWS. | |
""" | |
import boto3 | |
prompt_data = """Command: Write me a blog about making strong business decisions as a leader""" | |
AWS_REGION='us-east-1' | |
modelId = "amazon.titan-tg1-large" | |
accept = "application/json" | |
contentType = "application/json" | |
bedrock_client = boto3.client( | |
service_name='bedrock', | |
region_name=AWS_REGION | |
) | |
body = json.dumps({"inputText": prompt_data}) | |
response = bedrock_client.invoke_model( | |
body=body, modelId=modelId, accept=accept, contentType=contentType | |
) | |
response_body = json.loads(response.get("body").read()) | |
print(response_body.get("results")[0].get("outputText")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment