Skip to content

Commit 4d2f67c

Browse files
committed
Add document understanding example for Amazon Nova
1 parent 859a914 commit 4d2f67c

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed
Binary file not shown.

python/example_code/bedrock-runtime/models/amazon_nova/amazon_nova_text/document_understanding.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,26 @@
1313
# Set the model ID, e.g., Amazon Nova Lite.
1414
model_id = "amazon.nova-lite-v1:0"
1515

16-
# Start a conversation with the user message.
17-
user_message = "Describe the purpose of a 'hello world' program in one line."
16+
# Load the document
17+
with open("example-data/amazon-nova-service-cards.pdf", "rb") as file:
18+
document_bytes = file.read()
19+
20+
# Start a conversation with a user message and the document
1821
conversation = [
1922
{
2023
"role": "user",
21-
"content": [{"text": user_message}],
24+
"content": [
25+
{
26+
"text": "Briefly compare the models described in this document"
27+
},
28+
{
29+
"document": {
30+
"format": "pdf",
31+
"name": "Amazon Nova Service Cards",
32+
"source": {"bytes": document_bytes}
33+
}
34+
}
35+
],
2236
}
2337
]
2438

@@ -27,7 +41,7 @@
2741
response = client.converse(
2842
modelId=model_id,
2943
messages=conversation,
30-
inferenceConfig={"maxTokens": 512, "temperature": 0.5, "topP": 0.9},
44+
inferenceConfig={"maxTokens": 500, "temperature": 0.3},
3145
)
3246

3347
# Extract and print the response text.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
boto3==1.37.9
2-
botocore==1.37.9
1+
boto3==1.38.15
2+
botocore==1.38.15
33
colorama==0.4.6
44
iniconfig==2.0.0
55
jmespath==1.0.1
66
packaging==24.2
77
pluggy==1.5.0
88
pytest==8.3.4
99
python-dateutil==2.9.0.post0
10-
s3transfer==0.11.2
10+
s3transfer==0.12.0
1111
six==1.17.0
1212
urllib3==2.3.0

0 commit comments

Comments
 (0)