-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconverse_api.py
More file actions
46 lines (37 loc) · 1.11 KB
/
converse_api.py
File metadata and controls
46 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import boto3
import json
import uuid
s3_bucket = "billiaitest"
s3_key = "image.png"
bedrock = boto3.client("bedrock-runtime")
def summarize_document(bucket, key):
s3_uri = f"s3://{bucket}/{key}"
tool_use_id = str(uuid.uuid4())
messages = [
{
"role": "user",
"content": [
{
"toolUse": {
"name": "document",
"toolUseId": tool_use_id,
"input": {"s3Uri": s3_uri}
}
},
{"text": "Summarize the contents of this document."}
]
}
]
response = bedrock.invoke_model(
modelId="us.amazon.nova-lite-v1:0",
contentType="application/json",
accept="application/json",
body=json.dumps({"messages": messages})
)
response_body = json.loads(response['body'].read())
print(response_body)
summary = response_body['output']['message']['content'][0]['text']
return summary
summary = summarize_document(s3_bucket, s3_key)
print("Summary of the document:")
print(summary)