Skip to content

Commit 859a914

Browse files
committed
Add test document
1 parent 53df56b commit 859a914

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# snippet-start:[python.example_code.bedrock-runtime.DocumentUnderstanding_AmazonNovaText]
5+
# Use the Conversation API to send a text message to Amazon Nova.
6+
7+
import boto3
8+
from botocore.exceptions import ClientError
9+
10+
# Create a Bedrock Runtime client in the AWS Region you want to use.
11+
client = boto3.client("bedrock-runtime", region_name="us-east-1")
12+
13+
# Set the model ID, e.g., Amazon Nova Lite.
14+
model_id = "amazon.nova-lite-v1:0"
15+
16+
# Start a conversation with the user message.
17+
user_message = "Describe the purpose of a 'hello world' program in one line."
18+
conversation = [
19+
{
20+
"role": "user",
21+
"content": [{"text": user_message}],
22+
}
23+
]
24+
25+
try:
26+
# Send the message to the model, using a basic inference configuration.
27+
response = client.converse(
28+
modelId=model_id,
29+
messages=conversation,
30+
inferenceConfig={"maxTokens": 512, "temperature": 0.5, "topP": 0.9},
31+
)
32+
33+
# Extract and print the response text.
34+
response_text = response["output"]["message"]["content"][0]["text"]
35+
print(response_text)
36+
37+
except (ClientError, Exception) as e:
38+
print(f"ERROR: Can't invoke '{model_id}'. Reason: {e}")
39+
exit(1)
40+
41+
# snippet-end:[python.example_code.bedrock-runtime.DocumentUnderstanding_AmazonNovaText]

0 commit comments

Comments
 (0)