class Prompt (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.Bedrock.Alpha.Prompt |
![]() | github.com/aws/aws-cdk-go/awsbedrockalpha/v2#Prompt |
![]() | software.amazon.awscdk.services.bedrock.alpha.Prompt |
![]() | aws_cdk.aws_bedrock_alpha.Prompt |
![]() | @aws-cdk/aws-bedrock-alpha ยป Prompt |
Implements
IConstruct
, IDependable
, IResource
, IPrompt
Class to create (or import) a Prompt with CDK.
Prompts are a specific set of inputs that guide Foundation Models (FMs) on Amazon Bedrock to generate an appropriate response or output for a given task or instruction. You can optimize the prompt for specific use cases and models.
See also: https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-management.html
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,
});
Initializer
new Prompt(scope: Construct, id: string, props: PromptProps)
Parameters
- scope
Construct
- id
string
- props
Prompt
Props
**************************************************************************** CONSTRUCTOR ***************************************************************************.
Construct Props
Name | Type | Description |
---|---|---|
prompt | string | The name of the prompt. |
default | IPrompt | The Prompt Variant that will be used by default. |
description? | string | A description of what the prompt does. |
kms | IKey | The KMS key that the prompt is encrypted with. |
tags? | { [string]: string } | Tags to apply to the prompt. |
variants? | IPrompt [] | The variants of your prompt. |
promptName
Type:
string
The name of the prompt.
This will be used as the physical name of the prompt. Allowed Pattern: ^([0-9a-zA-Z][_-]?){1,100}$
defaultVariant?
Type:
IPrompt
(optional, default: No default variant provided.)
The Prompt Variant that will be used by default.
description?
Type:
string
(optional, default: No description provided.
Maximum Length: 200)
A description of what the prompt does.
kmsKey?
Type:
IKey
(optional, default: AWS owned and managed key.)
The KMS key that the prompt is encrypted with.
tags?
Type:
{ [string]: string }
(optional, default: No tags applied.)
Tags to apply to the prompt.
variants?
Type:
IPrompt
[]
(optional, default: No additional variants provided.)
The variants of your prompt.
Variants can use different messages, models, or configurations so that you can compare their outputs to decide the best variant for your use case. Maximum of 1 variants.
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
node | Node | The tree node. |
prompt | string | The ARN of the prompt. |
prompt | string | The ID of the prompt. |
prompt | string | The name of the prompt. |
prompt | string | The version of the prompt. |
stack | Stack | The stack in which this resource is defined. |
variants | IPrompt [] | The variants of the prompt. |
description? | string | The description of the prompt. |
kms | IKey | The KMS key that the prompt is encrypted with. |
static PROPERTY_INJECTION_ID | string | Uniquely identifies this class. |
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
node
Type:
Node
The tree node.
promptArn
Type:
string
The ARN of the prompt. Example
"arn:aws:bedrock:us-east-1:123456789012:prompt/PROMPT12345"
promptId
Type:
string
The ID of the prompt. Example
"PROMPT12345"
promptName
Type:
string
The name of the prompt.
promptVersion
Type:
string
The version of the prompt.
stack
Type:
Stack
The stack in which this resource is defined.
variants
Type:
IPrompt
[]
The variants of the prompt.
description?
Type:
string
(optional)
The description of the prompt.
kmsKey?
Type:
IKey
(optional)
The KMS key that the prompt is encrypted with.
static PROPERTY_INJECTION_ID
Type:
string
Uniquely identifies this class.
Methods
Name | Description |
---|---|
add | Adds a prompt variant to the prompt. |
apply | Apply the given removal policy to this resource. |
create | Creates a prompt version, a static snapshot of your prompt that can be deployed to production. |
grant | Grant the given identity permissions to get the prompt. |
to | Returns a string representation of this construct. |
static from | Creates a Prompt reference from an existing prompt's attributes. |
addVariant(variant)
public addVariant(variant: IPromptVariant): void
Parameters
- variant
IPrompt
โ - The prompt variant to add.Variant
Adds a prompt variant to the prompt.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
createVersion(description?)
public createVersion(description?: string): PromptVersion
Parameters
- description
string
โ - Optional description for the version.
Returns
Creates a prompt version, a static snapshot of your prompt that can be deployed to production.
grantGet(grantee)
public grantGet(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
โ - The IAM principal to grant permissions to.
Returns
Grant the given identity permissions to get the prompt.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
static fromPromptAttributes(scope, id, attrs)
public static fromPromptAttributes(scope: Construct, id: string, attrs: PromptAttributes): IPrompt
Parameters
- scope
Construct
โ - The construct scope. - id
string
โ - Identifier of the construct. - attrs
Prompt
โ - Attributes of the existing prompt.Attributes
Returns
Creates a Prompt reference from an existing prompt's attributes.