Experimental
@aws-cdk/aws-bedrock-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.
PromptVersion L1 construct
Class to create a Prompt Version with CDK.
Creates a version of the prompt. Use this to create a static snapshot of your prompt that can be deployed to production. Versions allow you to easily switch between different configurations for your prompt and update your application with the most appropriate version for your use-case.
Example
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,
});
const promptVersion = new bedrock.PromptVersion(this, 'MyPromptVersion', {
prompt: prompt1,
description: 'my first version',
});
//or alternatively:
// const promptVersion = prompt1.createVersion('my first version');
const versionString = promptVersion.version;
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
)
prompt_version = bedrock.PromptVersion(self, "MyPromptVersion",
prompt=prompt1,
description="my first version"
)
# or alternatively:
# const promptVersion = prompt1.createVersion('my first version');
version_string = prompt_version.version
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();
PromptVersion promptVersion = PromptVersion.Builder.create(this, "MyPromptVersion")
.prompt(prompt1)
.description("my first version")
.build();
//or alternatively:
// const promptVersion = prompt1.createVersion('my first version');
String versionString = promptVersion.getVersion();
// 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
});
var promptVersion = new PromptVersion(this, "MyPromptVersion", new PromptVersionProps {
Prompt = prompt1,
Description = "my first version"
});
//or alternatively:
// const promptVersion = prompt1.createVersion('my first version');
var versionString = promptVersion.Version;
// 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,
})
promptVersion := bedrock.NewPromptVersion(this, jsii.String("MyPromptVersion"), &PromptVersionProps{
Prompt: prompt1,
Description: jsii.String("my first version"),
})
//or alternatively:
// const promptVersion = prompt1.createVersion('my first version');
versionString := promptVersion.Version
Initializer
new PromptVersion(scope: Construct, id: string, props: PromptVersionProps)
PromptVersion(scope: Construct, id: str, props: PromptVersionProps)
new PromptVersion(Construct scope, String id, PromptVersionProps props)
new PromptVersion(Construct scope, string id, PromptVersionProps props)
NewPromptVersion(Scope Construct, Id *string, Props PromptVersionProps)
Construct Props
descriptionoptionalstringdescriptionoptionalstrdescriptionoptionalStringDescriptionoptionalstringDescriptionoptional*string#Default: No description provided. Maximum length: 200
Properties
descriptionmay be undefinedstringdescriptionmay be undefinedstrdescriptionmay be undefinedStringDescriptionmay be undefinedstringDescriptionmay be undefined*string#example
"arn:aws:bedrock:us-east-1:123456789012:prompt/PROMPT12345:1"
Methods
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.
1 parameter · returns
Parameters
mixinsmixinsmixinsmixinsMixins— The mixins to apply.
Returns: This construct for chaining