1 Answer
- Newest
- Most votes
- Most comments
1
To handle varying numbers of prompts in your AWS Lambda function, you can modify your code to dynamically build the "shots" section based on the non-empty prompts received. Here's how you can adjust your lambda_handler function:
- First, create a list of non-empty prompts:
prompts = [body['prompt'], body['prompt2'], body['prompt3']] non_empty_prompts = [p for p in prompts if p]
- Then, dynamically build the "shots" section:
shots = [{"text": prompt} for prompt in non_empty_prompts]
- Update your model_input dictionary:
model_input = { "taskType": "MULTI_SHOT_MANUAL", "multiShotManualParams": { "shots": shots }, "videoGenerationConfig": { "seed": 33, "fps": 24, "dimension": "1280x720", }, }
This approach ensures that only non-empty prompts are included in the "shots" section, while still allowing for up to three prompts. If there's only one prompt, the "shots" list will contain only that prompt. If there are two or three, it will include all of them.
Remember to handle potential errors if no prompts are provided:
if not non_empty_prompts: return { "statusCode": 400, "body": json.dumps({"error": "At least one prompt must be provided"}) }
This modification allows your Lambda function to flexibly handle varying numbers of prompts without sending empty ones to the Bedrock runtime.
Relevant content
asked a year ago
asked a year ago
- AWS OFFICIALUpdated 5 years ago
- AWS OFFICIALUpdated 5 years ago
