Package com.sap.ai.sdk.orchestration

# Class UserMessage

java.lang.Object
com.sap.ai.sdk.orchestration.UserMessage

All Implemented Interfaces:
  `Message`

public final class UserMessage extends Object implements Message
Represents a chat message as 'user' to the orchestration service.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `UserMessage(String message)`
  Creates a new user message from a string.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `MessageContent`
  `content()`
  The content of the message.
  `ChatMessage`
  `createChatMessage()`
  Converts the message to a serializable ChatMessage object.
  `boolean`
  `equals(Object o)`
  `int`
  `hashCode()`
  `String`
  `role()`
  The role of the assistant.
  `String`
  `toString()`
  `UserMessage`
  `withFile(Path filePath)`
  Add a file to the message by reading it from disk.
  `UserMessage`
  `withFileBase64(String base64Data, String filename)`
  Add a file to the message from a base64-encoded payload.
  `UserMessage`
  `withFileUrl(String fileUrl, String filename)`
  Add a file to the message by passing its URL.
  `UserMessage`
  `withImage(String imageUrl)`
  Add an image to the message with the given image URL.
  `UserMessage`
  `withImage(String imageUrl, ImageItem.DetailLevel detailLevel)`
  Add an image to the message with the given image URL and detail level.
  `UserMessage`
  `withText(String message)`
  Add text to the message.

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### UserMessage

    public UserMessage(@Nonnull String message)
    Creates a new user message from a string.
    Parameters:
      `message` - the first message.

- ## Method Details

  - ### withText

    @Nonnull public UserMessage withText(@Nonnull String message)
    Add text to the message.
    Parameters:
      `message` - the text to add.
    Returns:
      the new message.
    Since:
      1.3.0

  - ### withImage

    @Nonnull public UserMessage withImage(@Nonnull String imageUrl, @Nonnull ImageItem.DetailLevel detailLevel)
    Add an image to the message with the given image URL and detail level.
    Parameters:
      `imageUrl` - the URL of the image.
      `detailLevel` - the detail level of the image.
    Returns:
      the new message.
    Since:
      1.3.0

  - ### withImage

    @Nonnull public UserMessage withImage(@Nonnull String imageUrl)
    Add an image to the message with the given image URL.
    Parameters:
      `imageUrl` - the URL of the image.
    Returns:
      the new message.
    Since:
      1.3.0

  - ### withFile

    @Nonnull public UserMessage withFile(@Nonnull Path filePath)
    Add a file to the message by reading it from disk.
    Parameters:
      `filePath` - the path to a local file.
    Returns:
      the new message.
    Since:
      1.18.0

  - ### withFileUrl

    @Nonnull public UserMessage withFileUrl(@Nonnull String fileUrl, @Nullable String filename)
    Add a file to the message by passing its URL.
    Parameters:
      `fileUrl` - the URL of the file.
      `filename` - optional name of the file.
    Returns:
      the new message.
    Since:
      1.18.0

  - ### withFileBase64

    @Nonnull public UserMessage withFileBase64(@Nonnull String base64Data, @Nullable String filename)
    Add a file to the message from a base64-encoded payload.
    Parameters:
      `base64Data` - base64-encoded payload.
      `filename` - optional name of the file.
    Returns:
      the new message.
    Since:
      1.18.0

  - ### createChatMessage

    @Nonnull public ChatMessage createChatMessage()
    Description copied from interface: `Message`
    Converts the message to a serializable ChatMessage object.
    Specified by:
      `createChatMessage` in interface `Message`
    Returns:
      the corresponding `ChatMessage` object.

  - ### role

    @Nonnull public String role()
    The role of the assistant.
    Specified by:
      `role` in interface `Message`
    Returns:
      the role.

  - ### equals

    public boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### content

    @Nonnull public MessageContent content()
    The content of the message.
    Specified by:
      `content` in interface `Message`
    Returns:
      the content.