Class MotorStreamStatus

java.lang.Object
com.chatmotorapi.api.MotorStreamStatus

public class MotorStreamStatus
extends Object
Represents the status of a streamed request within the ChatMotor API, providing detailed information about the outcome of the operation. This class captures critical aspects of the streaming process, including success status, error details, and usage metrics that may impact the handling and interpretation of streamed data. Instances of MotorStreamStatus are generated as a result of streamed operations, primarily used to convey the success or failure of such requests. The status includes:
  • A boolean indicating overall success or failure.
  • MotorCompletionUsage detailing usage metrics during the stream.
  • Throwable capturing any exceptions that were thrown.
  • OpenAiErrorType indicating the type of error, if applicable.
// Execute the request and display immediately the response // in the console. // This uses a dedicated listener MotorResponseListener listener = new ConsoleResponseListener(); MotorStreamStatus status = motorRequest.executeAsStream(listener); // Check if the response is OK. if (status.isResponseOk()) { // Nothing to do here. Display is done by the listener. } else { // We check if the response is an OpenAI error and get the OpenAI error details // (type and message) OpenAiError openAiError = status.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 : " + status.getThrowable()); } }
  • Method Details

    • isResponseOk

      public boolean isResponseOk()
      Checks if the response was okay without any errors.
      Returns:
      true if the operation was successful, false otherwise.
    • getThrowable

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

      public MotorCompletionUsage getMotorCompletionUsage()
      Retrieves any specific MotorCompletionUsage that occurred during the operation. Maybe null for non chat requests.
      Returns:
      the motorCompletionUsage, or null if none occurred.
    • 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.