Package com.sap.ai.sdk.orchestration

# Class OrchestrationChatResponse

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

public final class OrchestrationChatResponse extends Object
Orchestration chat completion output.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `<T> T`
  `asEntity(Class<T> type)`
  Transform a JSON response into an entity of the given type.
  `boolean`
  `equals(Object o)`
  `List<Message>`
  `getAllMessages()`
  Get all messages.
  `LLMChoice`
  `getChoice()`
  Get the LLM response.
  `String`
  `getContent()`
  Get the message content from the output.
  `Message`
  `getLastMessage()`
  Get the last message in the response, which is the assistant's reply.
  `CompletionPostResponse`
  `getOriginalResponse()`
  `TokenUsage`
  `getTokenUsage()`
  Get the token usage.
  `int`
  `hashCode()`
  `String`
  `toString()`

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

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

- ## Method Details

  - ### getContent

    @Nonnull public String getContent() throws OrchestrationFilterException.Output
    Get the message content from the output.

    Note: If there are multiple choices only the first one is returned

    Returns:
      the message content or empty string.
    Throws:
      `OrchestrationFilterException.Output` - if the content filter filtered the output.

  - ### getTokenUsage

    @Nonnull public TokenUsage getTokenUsage()
    Get the token usage.
    Returns:
      The token usage.

  - ### getAllMessages

    @Nonnull public List<Message> getAllMessages() throws IllegalArgumentException
    Get all messages. This can be used for subsequent prompts as a message history.
    Returns:
      A list of all messages.
    Throws:
      `IllegalArgumentException` - if the MultiChatMessage type message in chat.

  - ### getChoice

    @Nonnull public LLMChoice getChoice()
    Get the LLM response. Useful for accessing the finish reason or further data like logprobs.
    Returns:
      The (first, in case of multiple) `LLMChoice`.

  - ### asEntity

    @Nonnull public <T> T asEntity(@Nonnull Class<T> type) throws OrchestrationClientException
    Transform a JSON response into an entity of the given type.

    This is possible on a request with a `OrchestrationTemplate.withJsonSchemaResponse(com.sap.ai.sdk.orchestration.ResponseJsonSchema)` configured into `OrchestrationModuleConfig.withTemplateConfig(com.sap.ai.sdk.orchestration.TemplateConfig)`.

    Type Parameters:
      `T` - the type of the entity to deserialize to.
    Parameters:
      `type` - the class type to deserialize the JSON content into.
    Returns:
      the deserialized entity of type T.
    Throws:
      `OrchestrationClientException` - if the model refused to answer the question or if the content

  - ### getLastMessage

    @Nonnull public Message getLastMessage()
    Get the last message in the response, which is the assistant's reply.
    Returns:
      The assistant's reply message.

  - ### getOriginalResponse

    public CompletionPostResponse getOriginalResponse()

  - ### 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`