Class MotorResponse

java.lang.Object
com.chatmotorapi.api.MotorResponse
All Implemented Interfaces:
MotorResponseType

public class MotorResponse
extends Object
implements MotorResponseType
Represents the response from executing a MotorRequest. This class encapsulates all details relevant to the response including any errors, usage metrics, and the actual content of the response. Instances of this class are not created directly but are produced as a result of executing requests made by MotorRequest. The class provides methods to access these details, allowing for thorough analysis and processing of the response from the ChatMotor API.

The response class includes status indicators to check the success of the request, detailed error messages if applicable, usage statistics related to the request, and the response data itself.


// Execute the request.
MotorResponse motorResponse = motorRequest.execute();

// We check if the response is OK.
if (motorResponse.isResponseOk()) {
    // OK, print the response.
    String response = motorResponse.getResponse();
    System.out.println(response);
} else {
    // We check if the response is an OpenAI error and get the OpenAI error details
    // (type and message)
    OpenAiError openAiError = motorResponse.getOpenAiError();
    OpenAiErrorType errorType = openAiError.getType();

    if (errorType != OpenAiErrorType.NO_OPENAI_ERROR) {
        System.out.println("OpenAI has returned an error : " + openAiError);
    } else {
        System.out.println("throwable   : " + motorResponse.getThrowable());
    }
}
  • Constructor Details

    • MotorResponse

      public MotorResponse()
  • Method Details

    • getMotorCompletionUsage

      public MotorCompletionUsage getMotorCompletionUsage()
      Gets the usage details of the response.
      Returns:
      the usage object containing metrics associated with the request
    • isResponseOk

      public boolean isResponseOk()
      Returns whether the response was successfully processed.
      Returns:
      true if the response was processed successfully; otherwise, false
    • getResponse

      public String getResponse()
      Gets the main content of the response.
      Returns:
      the response content
    • getThrowable

      public Throwable getThrowable()
      Gets the throwable associated with the response.
      Returns:
      the throwable, or a MotorNoExceptionThrown instance if there is no throwable.
    • getOpenAiError

      public OpenAiError getOpenAiError()
      Gets the OpenAI error associated with the response.
      Returns:
      the OpenAiError
    • toString

      public String toString()
      Provides a string representation of this object. The output includes the class name along with key attribute values.
      Overrides:
      toString in class Object
      Returns:
      a string description of this object.