ChatMessage
- class aws_cdk.aws_bedrock_alpha.ChatMessage(role, text)
Bases:
object
(experimental) Represents a message in a chat conversation.
- Stability:
experimental
- ExampleMetadata:
fixture=default infused
Example:
cmk = kms.Key(self, "cmk") variant_chat = bedrock.PromptVariant.chat( variant_name="variant1", model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0, messages=[ bedrock.ChatMessage.user("From now on, you speak Japanese!"), bedrock.ChatMessage.assistant("Konnichiwa!"), bedrock.ChatMessage.user("From now on, you speak {{language}}!") ], system="You are a helpful assistant that only speaks the language you`re told.", prompt_variables=["language"], tool_configuration=bedrock.ToolConfiguration( tool_choice=bedrock.ToolChoice.AUTO, tools=[ bedrock.Tool.function( name="top_song", description="Get the most popular song played on a radio station.", input_schema={ "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"] } ) ] ) ) bedrock.Prompt(self, "prompt1", prompt_name="prompt-chat", description="my first chat prompt", default_variant=variant_chat, variants=[variant_chat], kms_key=cmk )
- Parameters:
role (
ChatMessageRole
)text (
str
)
- Stability:
experimental
Attributes
- role
(experimental) The role of the message sender.
- Stability:
experimental
- text
(experimental) The text content of the message.
- Stability:
experimental
Static Methods
- classmethod assistant(text)
(experimental) Creates an assistant message.
- Parameters:
text (
str
) –The text content of the assistant message.
- Return type:
- Returns:
A ChatMessage instance representing an assistant message
- Stability:
experimental
- classmethod user(text)
(experimental) Creates a user message.
- Parameters:
text (
str
) –The text content of the user message.
- Return type:
- Returns:
A ChatMessage instance representing a user message
- Stability:
experimental