Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bedrock): add prompt chat templates #876

Merged
merged 10 commits into from
Jan 6, 2025

Conversation

aws-rafams
Copy link
Contributor

@aws-rafams aws-rafams commented Jan 6, 2025

Fixes #872

Note: to be able to merge this PR, it requires a CDK version bump from 2.166.0 to 2.174.0

Sample usage:

const cmk = new kms.Key(this, 'cmk', {});

const variantChat = PromptVariant.chat({
  variantName: 'variant1',
  model: BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
  system: 'You are a helpful assistant that only speaks the language you`re told.',
  messages: [
    ChatMessage.user('From now on, you speak Japanese!'),
    ChatMessage.assistant('Konnichiwa!'),
    ChatMessage.user('From now on, you speak {{language}}!'),
  ],
  promptVariables: ['language'],
  toolConfiguration: {
    toolChoice: ToolChoice.AUTO,
    tools: [
      {
        toolSpec: {
          name: 'top_song',
          description: 'Get the most popular song played on a radio station.',
          inputSchema: {
            json: {
              type: 'object',
              properties: {
                sign: {
                  type: 'string',
                  description:
                    'The call sign for the radio station for which you want the most popular song. Example calls signs are WZPZ and WKR.',
                },
              },
              required: ['sign'],
            },
          },
        },
      },
    ],
  },
});

new Prompt(stack, 'prompt1', {
  promptName: 'prompt-chat',
  description: 'my first chat prompt',
  defaultVariant: variantChat,
  variants: [variantChat],
  kmsKey: cmk,
});

AWS Console
Screenshot 2025-01-06 at 14 24 09


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

@aws-rafams aws-rafams changed the title Prompt update feat(bedrock): add prompt chat templates Jan 6, 2025
@krokoko
Copy link
Collaborator

krokoko commented Jan 6, 2025

One thing: by upgrading to the latest cdk version, some tests are failing since the latest available Python version is 3.13. Currently, most lambdas are using 3.12, including the CRs. We can add a cdk nag suppress for now and do the upgrade in a separate PR since it will require some testing

@krokoko
Copy link
Collaborator

krokoko commented Jan 6, 2025

The go packaging is an issue with CDK v2.174 (see here ).

krokoko
krokoko previously approved these changes Jan 6, 2025
@krokoko krokoko self-requested a review January 6, 2025 16:21
@krokoko krokoko merged commit c529758 into awslabs:main Jan 6, 2025
13 of 14 checks passed
@aws-rafams aws-rafams deleted the prompt-update branch January 7, 2025 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(bedrock): update prompt support
4 participants