Skip to content

Instantly share code, notes, and snippets.

@liangfu
Created October 14, 2024 19:17
Show Gist options
  • Save liangfu/df45b317677942f73807ade6b4b42d78 to your computer and use it in GitHub Desktop.
Save liangfu/df45b317677942f73807ade6b4b42d78 to your computer and use it in GitHub Desktop.
Ask Bedrock long questions with Python script
import boto3, json
question = """
How are you today?
"""
def main():
session = boto3.Session()
bedrock = session.client(service_name='bedrock-runtime', region_name="us-west-2")
message_list = []
initial_message = {
"role": "user",
"content": [
{ "text": question }
],
}
message_list.append(initial_message)
response = bedrock.converse(
modelId="anthropic.claude-3-5-sonnet-20240620-v1:0",
messages=message_list,
inferenceConfig={
"maxTokens": 2000,
"temperature": 0
},
)
response_message = response['output']['message']["content"][0]["text"]
print(response_message)
if __name__=="__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment