Skip to content

Commit d3d8a85

Browse files
committed
work on list flows calling code
1 parent 5486d4f commit d3d8a85

File tree

5 files changed

+63
-7
lines changed

5 files changed

+63
-7
lines changed

.doc_gen/metadata/bedrock-agent_metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ bedrock-agent_GettingStartedWithBedrockFlows:
240240

241241
services:
242242
bedrock-agent: {CreateFlow, CreateFlowAlias, CreateFlowVersion, DeleteFlow, DeleteFlowVersion, DeleteFlowAlias, GetFlow, GetFlowAlias,
243-
GetFlowVersion, ListFlows, ListFlowVersions, ListFLowAliases, PrepareFlow}
243+
GetFlowVersion, PrepareFlow}
244244
bedrock-agent-runtime: {InvokeFlow}
245245

246246

python/example_code/bedrock-agent/flows/flow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def list_flows(client):
236236
flow_id (str): The identifier of the flow.
237237
238238
Returns:
239-
dict: The response from ListFlowVersions.
239+
Nothing.
240240
"""
241241
try:
242242
finished = False
@@ -262,8 +262,8 @@ def list_flows(client):
262262
else:
263263
finished = True
264264

265-
logging.info("Successfully listed flows")
266-
return response
265+
logging.info("Successfully listed flows.")
266+
267267

268268
except ClientError as e:
269269
logging.exception("Client error listing flow versions: %s", str(e))
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""
5+
Amazon Bedrock Flow lists
6+
7+
Shows how to list Amazon Bedrock flows, flow versions in a flow,
8+
and flow aliases in a flow.
9+
10+
"""
11+
12+
import logging
13+
import boto3
14+
15+
from botocore.exceptions import ClientError
16+
17+
18+
from flow import list_flows
19+
from flow_version import list_flow_versions
20+
from flow_alias import list_flow_aliases
21+
22+
23+
def main():
24+
"""
25+
List the Amazon Bedrock flows, flow versions in a flow,
26+
and flow aliases in a flow. The call to List_flows shows
27+
the IDs that you can enter for the flow ID.
28+
29+
Note:
30+
Requires valid AWS credentials in the default profile.
31+
"""
32+
33+
try:
34+
35+
session = boto3.Session(profile_name='default')
36+
bedrock_agent_client = session.client('bedrock-agent')
37+
38+
print("Listing flows")
39+
list_flows(bedrock_agent_client)
40+
flow_id = input("Enter Flow ID: ")
41+
print(f"Listing flow versions for flow {flow_id}")
42+
list_flow_versions(bedrock_agent_client, flow_id)
43+
print(f"Listing flow aliases for flow {flow_id}")
44+
list_flow_aliases(bedrock_agent_client, flow_id)
45+
46+
except ClientError as e:
47+
logging.exception("Client error running example: %s", str(e))
48+
49+
except Exception as e:
50+
print(f"Fatal error: {str(e)}")
51+
52+
finally:
53+
print ("Done")
54+
55+
if __name__ == "__main__":
56+
main()
57+

python/example_code/bedrock-agent/test/test_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def test_list_flows(make_stubber, error_code):
264264
call_response = flow.list_flows(
265265
bedrock_agent_client)
266266

267-
assert call_response is not None
267+
assert call_response is None
268268

269269
else:
270270
with pytest.raises(ClientError) as exc_info:

python/example_code/bedrock-agent/test/test_playlist_flow.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
@pytest.mark.parametrize("file", files_under_test)
1414
def test_playlist_flow(file):
1515
# Simulate user input - each string represents one input() call
16-
# If you're using the docs at https://docs.aws.amazon.com/bedrock/latest/userguide/flows-multi-turn-invocation.html,
17-
# "Create a playlist\n 3\n pop, castles\n" should work with Antropic Haiku.
16+
# Creates a playlist of 3 pop songs.
1817
test_input = "pop\n3\ny"
1918

2019
result = subprocess.run(

0 commit comments

Comments
 (0)