Skip to content

Passing in prompts to aws lambda function.

0

My android studio code in Kotlin is passing one single prompt for my original aws lambda function, but my new function expects more than one prompt as this is nova reels multi shots. In the code below, how can i pass the same type of prompt the same way, twice, in order to retrieve each specific prompt in my aws lambda function and use them as the string for the "text": section.

val userPromptvc = inputFieldvc.text.toString()

val jsonPayload = "{"prompt":"$userPromptvc"}"

val requestBody = jsonPayload.toRequestBody("application/json".toMediaType())

val request = Request.Builder() .url(url) .post(requestBody) .build()

asked a year ago116 views

1 Answer
0

To pass multiple prompts to your AWS Lambda function for Nova Reels multi-shots, you can modify your Kotlin code to include multiple prompts in the JSON payload. Here's how you can adjust your code to pass two prompts:

  1. First, ensure you have two input fields or a way to capture two separate prompts from the user.

  2. Then, modify your code to create a JSON payload with both prompts:

val userPrompt1 = inputField1.text.toString()
val userPrompt2 = inputField2.text.toString()

val jsonPayload = """
    {
        "prompt1": "$userPrompt1",
        "prompt2": "$userPrompt2"
    }
""".trimIndent()

val requestBody = jsonPayload.toRequestBody("application/json".toMediaType())

val request = Request.Builder()
    .url(url)
    .post(requestBody)
    .build()

In your AWS Lambda function, you can then retrieve these prompts from the event parameter:

def lambda_handler(event, context):
    # Extract the prompts from the event
    body = json.loads(event['body'])
    prompt1 = body['prompt1']
    prompt2 = body['prompt2']

    model_input = {
        "taskType": "TEXT_VIDEO",
        "textToVideoParams": [
            {"text": prompt1},
            {"text": prompt2}
        ],
        "videoGenerationConfig": {
            "durationSeconds": 6,
            "fps": 24,
            "dimension": "1280x720",
            "seed": 33,
        },
    }

    # Rest of your Lambda function code...

This approach allows you to send multiple prompts from your Android app to your Lambda function, which can then use them for the Nova Reels multi-shot feature. Remember to adjust the Lambda function to handle multiple prompts in the textToVideoParams section of the model_input dictionary.
Sources
Changing AWS Lambda Function prompt value with an event instead of changing environment variable. | AWS re:Post
i need to pass an event with my string, to my AWS Lambda function, to use as the prompt to communicate with amazon bedrock. | AWS re:Post

answered a year ago

AWS
SUPPORT ENGINEER

reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.