Skip to content

Bedrock Prompt Management: Only allowing 1 prompt variant per prompt #988

@jantmer

Description

@jantmer

Describe the bug

Trying to deploy a prompt with 2 variants and getting an error that it only expected 1 variant.

Expected Behavior

According to the construct definition: https://github.com/awslabs/generative-ai-cdk-constructs/blob/main/src/cdk-lib/bedrock/prompts/prompt.ts

It should allow a maximum of 3 variants.

Current Behavior

Getting the following error:

❌ PromptManagerStack failed: Error: The stack named PromptManagerStack failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: Properties validation failed for resource flightParametersPromptE31C7D46 with message:
[#/Variants: expected maximum item count: 1, found: 2]

Reproduction Steps

Code:
`from aws_cdk import (
Stack
)
from cdklabs.generative_ai_cdk_constructs import (
bedrock
)
from constructs import Construct
import os

class PromptManagerStack(Stack):

def load_text(self, file_name):
    try:
        current_dir = os.path.dirname(os.path.abspath(__file__))
        absolute_path = os.path.join(current_dir, "..", "prompts", file_name)
        with open(absolute_path, "r") as file:
            return file.read()
    except FileNotFoundError:
        raise FileNotFoundError(f"Could not find prompt file at {absolute_path}. Please verify the file exists and the path is correct.")

def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
    super().__init__(scope, construct_id, **kwargs)

    #Bedrock Prompt Management - Flight Parameters Prompt

    # For regions and models that require Cross Region Inference, we must create an inference profile
    cris_nova_micro = bedrock.CrossRegionInferenceProfile.from_config(
            geo_region= bedrock.CrossRegionInferenceProfileRegion.US,
            model= bedrock.BedrockFoundationModel.AMAZON_NOVA_MICRO_V1
            )
    
    flightParametersText = self.load_text("flightParameters.txt")
    flightParameters2Text = self.load_text("flightParameters2.txt")
    
    #Create a prompt version with version1 of prompt with Haiku3 - best accuracy       
    flightParametersV1 = bedrock.PromptVariant.text(
        variant_name="V1-Haiku3",
        model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_HAIKU_V1_0,
        prompt_variables=["customer_name", "current_date", "conversation_history", "language", "station_mapping"],
        prompt_text= flightParametersText,
        inference_configuration={
            "temperature": 0.0,
            "top_p": 0.999,
            "max_tokens": 500,
        }
    )
    
    #Create a prompt version the second version of prompt and Nova Micro - best latency       
    flightParametersV2 = bedrock.PromptVariant.text(
        variant_name="V2-Nova-Micro",
        model=cris_nova_micro,
        prompt_variables=["customer_name", "current_date", "conversation_history", "language", "station_mapping"],
        prompt_text= flightParameters2Text,
        inference_configuration={
            "temperature": 0.0,
            "top_p": 0.999,
            "max_tokens": 500,
        }
    )

    # Define the actual prompt with the different associated versions, and a default version. When running the inference you can decide which version to use.
    flightParametersPrompt = bedrock.Prompt(
        self,
        "flightParameters Prompt",
        prompt_name="FlightParameters",
        description="Prompt for extracting api parameters for flight search from conversation with customer.",
        default_variant=flightParametersV2,
        variants=[flightParametersV1, flightParametersV2]
    )

`

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.175.1

Framework Version

v0.1.293

Node.js Version

v20.17.0

OS

macos Sonoma

Language

Python

Language Version

3.13.1

Region experiencing the issue

us-west-2

Code modification

N/A

Other information

No response

Service quota

  • I have reviewed the service quotas for this construct

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlogbugSomething isn't workingpending-cfn-updateThis issue requires CloudFormation schema to be updated before work can begin

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions