Skip to content

Commit 5f5b3dc

Browse files
committed
updates for review feedback
1 parent 687d744 commit 5f5b3dc

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

python/example_code/bedrock-agent/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,7 @@ Start the example by running the following at a command prompt:
194194
python prompts/list_prompts.py
195195
```
196196

197-
The example first lists the prompts in the current AWS Region. It
198-
then prompts for a prompt ID, which you can get from the list of prompts. Finally, the example lists the prompt versions for the prompt ID that you entered.
199-
197+
The example first lists the prompts in the current AWS Region.
200198

201199

202200
### Tests

python/example_code/bedrock-agent/prompts/prompt.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,13 @@ def get_prompt(client, prompt_id):
157157

158158

159159
# snippet-start:[python.example_code.bedrock.delete_prompt]
160-
def delete_prompt(client, prompt_id, skip_resource_in_use_check=False):
160+
def delete_prompt(client, prompt_id):
161161
"""
162162
Deletes an Amazon Bedrock managed prompt.
163163
164164
Args:
165165
client: Amazon Bedrock Agent boto3 client.
166166
prompt_id (str): The identifier of the prompt that you want to delete.
167-
skip_resource_in_use_check (bool, optional): Whether to skip checking if the prompt is in use.
168-
This parameter is ignored as it's not supported by the API.
169167
170168
Returns:
171169
dict: The response from the DeletePrompt operation.
@@ -191,6 +189,7 @@ def delete_prompt(client, prompt_id, skip_resource_in_use_check=False):
191189
# snippet-end:[python.example_code.bedrock.delete_prompt]
192190

193191
# snippet-start:[python.example_code.bedrock.list_prompts]
192+
194193
def list_prompts(client, max_results=10):
195194
"""
196195
Lists Amazon Bedrock managed prompts.
@@ -203,32 +202,31 @@ def list_prompts(client, max_results=10):
203202
list: A list of prompt summaries.
204203
"""
205204
try:
206-
finished = False
207-
all_prompts = []
208-
next_token = None
209-
210205
logger.info("Listing prompts:")
211-
212-
while not finished:
213-
if next_token:
214-
response = client.list_prompts(maxResults=max_results, nextToken=next_token)
215-
else:
216-
response = client.list_prompts(maxResults=max_results)
217-
218-
all_prompts.extend(response.get('promptSummaries', []))
219-
220-
if 'nextToken' in response:
221-
next_token = response['nextToken']
222-
else:
223-
finished = True
224-
206+
207+
# Create a paginator for the list_prompts operation
208+
paginator = client.get_paginator('list_prompts')
209+
210+
# Create the pagination parameters
211+
pagination_config = {
212+
'maxResults': max_results
213+
}
214+
215+
# Initialize an empty list to store all prompts
216+
all_prompts = []
217+
218+
# Iterate through all pages
219+
for page in paginator.paginate(**pagination_config):
220+
all_prompts.extend(page.get('promptSummaries', []))
221+
225222
logger.info("Successfully listed %s prompts.", len(all_prompts))
226223
return all_prompts
227-
224+
228225
except ClientError as e:
229226
logger.exception("Client error listing prompts: %s", str(e))
230227
raise
231228
except Exception as e:
232229
logger.exception("Unexpected error listing prompts: %s", str(e))
233230
raise
231+
234232
# snippet-end:[python.example_code.bedrock.list_prompts]

0 commit comments

Comments
 (0)