Experimental
@aws-cdk/aws-bedrock-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.
PromptVariant Class
Factory class for creating prompt variants.
Provides static methods to create different types of prompt variants with proper configuration and type safety.
| Stability | Experimental |
|---|---|
| Source | bedrock/prompts/prompt-variant.ts |
Example
ts
const cmk = new kms.Key(this, 'cmk', {});
const claudeModel = bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0;
const variant1 = bedrock.PromptVariant.text({
variantName: 'variant1',
model: claudeModel,
promptVariables: ['topic'],
promptText: 'This is my first text prompt. Please summarize our conversation on: {{topic}}.',
inferenceConfiguration: bedrock.PromptInferenceConfiguration.text({
temperature: 1.0,
topP: 0.999,
maxTokens: 2000,
}),
});
const prompt1 = new bedrock.Prompt(this, 'prompt1', {
promptName: 'prompt1',
description: 'my first prompt',
defaultVariant: variant1,
variants: [variant1],
kmsKey: cmk,
});
python
cmk = kms.Key(self, "cmk")
claude_model = bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0
variant1 = bedrock.PromptVariant.text(
variant_name="variant1",
model=claude_model,
prompt_variables=["topic"],
prompt_text="This is my first text prompt. Please summarize our conversation on: {{topic}}.",
inference_configuration=bedrock.PromptInferenceConfiguration.text(
temperature=1,
top_p=0.999,
max_tokens=2000
)
)
prompt1 = bedrock.Prompt(self, "prompt1",
prompt_name="prompt1",
description="my first prompt",
default_variant=variant1,
variants=[variant1],
kms_key=cmk
)
java
Key cmk = Key.Builder.create(this, "cmk").build();
BedrockFoundationModel claudeModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0;
IPromptVariant variant1 = PromptVariant.text(TextPromptVariantProps.builder()
.variantName("variant1")
.model(claudeModel)
.promptVariables(List.of("topic"))
.promptText("This is my first text prompt. Please summarize our conversation on: {{topic}}.")
.inferenceConfiguration(PromptInferenceConfiguration.text(PromptInferenceConfigurationProps.builder()
.temperature(1)
.topP(0.999)
.maxTokens(2000)
.build()))
.build());
Prompt prompt1 = Prompt.Builder.create(this, "prompt1")
.promptName("prompt1")
.description("my first prompt")
.defaultVariant(variant1)
.variants(List.of(variant1))
.kmsKey(cmk)
.build();
csharp
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Alpha
var cmk = new Key(this, "cmk", new KeyProps { });
var claudeModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0;
var variant1 = PromptVariant.Text(new TextPromptVariantProps {
VariantName = "variant1",
Model = claudeModel,
PromptVariables = new [] { "topic" },
PromptText = "This is my first text prompt. Please summarize our conversation on: {{topic}}.",
InferenceConfiguration = PromptInferenceConfiguration.Text(new PromptInferenceConfigurationProps {
Temperature = 1,
TopP = 0.999,
MaxTokens = 2000
})
});
var prompt1 = new Prompt(this, "prompt1", new PromptProps {
PromptName = "prompt1",
Description = "my first prompt",
DefaultVariant = variant1,
Variants = new [] { variant1 },
KmsKey = cmk
});
go
// Install: go get github.com/aws/aws-cdk-go/awsbedrockalpha/v2
cmk := kms.NewKey(this, jsii.String("cmk"), &KeyProps{
})
claudeModel := bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_SONNET_V1_0()
variant1 := bedrock.PromptVariant_Text(&TextPromptVariantProps{
VariantName: jsii.String("variant1"),
Model: claudeModel,
PromptVariables: []*string{
jsii.String("topic"),
},
PromptText: jsii.String("This is my first text prompt. Please summarize our conversation on: {{topic}}."),
InferenceConfiguration: bedrock.PromptInferenceConfiguration_Text(&PromptInferenceConfigurationProps{
Temperature: jsii.Number(1),
TopP: jsii.Number(0.999),
MaxTokens: jsii.Number(2000),
}),
})
prompt1 := bedrock.NewPrompt(this, jsii.String("prompt1"), &PromptProps{
PromptName: jsii.String("prompt1"),
Description: jsii.String("my first prompt"),
DefaultVariant: variant1,
Variants: []IPromptVariant{
variant1,
},
KmsKey: cmk,
})
Methods
agent(props: AgentPromptVariantProps): IPromptVariant@staticmethod def agent(props: AgentPromptVariantProps) -> IPromptVariantpublic static IPromptVariant agent(AgentPromptVariantProps props)public static IPromptVariant Agent(AgentPromptVariantProps props)func Agent(Props AgentPromptVariantProps) IPromptVariant static #Creates an agent prompt template variant.
1 parameter · returns
Parameters
propspropspropspropsProps— - Properties for the agent prompt variant.
Returns: A PromptVariant configured for agent interactions
chat(props: ChatPromptVariantProps): IPromptVariant@staticmethod def chat(props: ChatPromptVariantProps) -> IPromptVariantpublic static IPromptVariant chat(ChatPromptVariantProps props)public static IPromptVariant Chat(ChatPromptVariantProps props)func Chat(Props ChatPromptVariantProps) IPromptVariant static #Creates a chat template variant.
Use this template type when the model supports the Converse API or the Anthropic Claude Messages API. This allows you to include a System prompt and previous User messages and Assistant messages for context.
1 parameter · returns
Parameters
propspropspropspropsProps— - Properties for the chat prompt variant.
Returns: A PromptVariant configured for chat interactions
text(props: TextPromptVariantProps): IPromptVariant@staticmethod def text(props: TextPromptVariantProps) -> IPromptVariantpublic static IPromptVariant text(TextPromptVariantProps props)public static IPromptVariant Text(TextPromptVariantProps props)func Text(Props TextPromptVariantProps) IPromptVariant static #Creates a text template variant.
1 parameter · returns
Parameters
propspropspropspropsProps— - Properties for the text prompt variant.
Returns: A PromptVariant configured for text processing