java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.services.bedrock.alpha.ChatMessage
All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable

@Generated(value="jsii-pacmak/1.112.0 (build de1bc80)", date="2025-07-24T11:33:25.536Z") @Stability(Experimental) public class ChatMessage extends software.amazon.jsii.JsiiObject
(experimental) Represents a message in a chat conversation.

Example:

 Key cmk = Key.Builder.create(this, "cmk").build();
 IPromptVariant variantChat = PromptVariant.chat(ChatPromptVariantProps.builder()
         .variantName("variant1")
         .model(BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0)
         .messages(List.of(ChatMessage.user("From now on, you speak Japanese!"), ChatMessage.assistant("Konnichiwa!"), ChatMessage.user("From now on, you speak {{language}}!")))
         .system("You are a helpful assistant that only speaks the language you`re told.")
         .promptVariables(List.of("language"))
         .toolConfiguration(ToolConfiguration.builder()
                 .toolChoice(ToolChoice.AUTO)
                 .tools(List.of(Tool.function(FunctionToolProps.builder()
                         .name("top_song")
                         .description("Get the most popular song played on a radio station.")
                         .inputSchema(Map.of(
                                 "type", "object",
                                 "properties", Map.of(
                                         "sign", Map.of(
                                                 "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", List.of("sign")))
                         .build())))
                 .build())
         .build());
 Prompt.Builder.create(this, "prompt1")
         .promptName("prompt-chat")
         .description("my first chat prompt")
         .defaultVariant(variantChat)
         .variants(List.of(variantChat))
         .kmsKey(cmk)
         .build();
 
  • Nested Class Summary

    Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject

    software.amazon.jsii.JsiiObject.InitializationMode
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
     
    protected
    ChatMessage(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
     
    protected
    ChatMessage(software.amazon.jsii.JsiiObjectRef objRef)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (experimental) Creates an assistant message.
    (experimental) The role of the message sender.
    (experimental) The text content of the message.
    user(String text)
    (experimental) Creates a user message.

    Methods inherited from class software.amazon.jsii.JsiiObject

    jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface software.amazon.jsii.JsiiSerializable

    $jsii$toJson
  • Constructor Details

    • ChatMessage

      protected ChatMessage(software.amazon.jsii.JsiiObjectRef objRef)
    • ChatMessage

      protected ChatMessage(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • ChatMessage

      @Stability(Experimental) public ChatMessage(@NotNull ChatMessageRole role, @NotNull String text)
      Parameters:
      role - This parameter is required.
      text - This parameter is required.
  • Method Details

    • assistant

      @Stability(Experimental) @NotNull public static ChatMessage assistant(@NotNull String text)
      (experimental) Creates an assistant message.

      Parameters:
      text -
      • The text content of the assistant message.
      This parameter is required.
      Returns:
      A ChatMessage instance representing an assistant message
    • user

      @Stability(Experimental) @NotNull public static ChatMessage user(@NotNull String text)
      (experimental) Creates a user message.

      Parameters:
      text -
      • The text content of the user message.
      This parameter is required.
      Returns:
      A ChatMessage instance representing a user message
    • getRole

      @Stability(Experimental) @NotNull public ChatMessageRole getRole()
      (experimental) The role of the message sender.
    • getText

      @Stability(Experimental) @NotNull public String getText()
      (experimental) The text content of the message.