Package com.chatmotorapi.api
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 Summary
Constructors Constructor Description MotorResponse()
-
Method Summary
Modifier and Type Method Description MotorCompletionUsage
getMotorCompletionUsage()
Gets the usage details of the response.OpenAiError
getOpenAiError()
Gets the OpenAI error associated with the response.String
getResponse()
Gets the main content of the response.Throwable
getThrowable()
Gets the throwable associated with the response.boolean
isResponseOk()
Returns whether the response was successfully processed.String
toString()
Provides a string representation of this object.
-
Constructor Details
-
MotorResponse
public MotorResponse()
-
-
Method Details
-
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
Gets the main content of the response.- Returns:
- the response content
-
getThrowable
Gets the throwable associated with the response.- Returns:
- the throwable, or a MotorNoExceptionThrown instance if there is no throwable.
-
getOpenAiError
Gets the OpenAI error associated with the response.- Returns:
- the OpenAiError
-
toString
Provides a string representation of this object. The output includes the class name along with key attribute values.
-