Package com.chatmotorapi.api.image
Class MotorImageResponse
java.lang.Object
com.chatmotorapi.api.image.MotorImageResponse
- All Implemented Interfaces:
MotorResponseType
public class MotorImageResponse extends Object implements MotorResponseType
Represents the response from an image processing request made through the
ChatMotor API, specifically tailored for interactions with OpenAI's Image
API. This class encapsulates the outcome of the request, including any
generated images, errors encountered, and exceptions thrown during the
process.
An instance of
MotorImageResponse
is typically obtained by executing
a MotorImageRequest
and contains critical information about the
success or failure of the request. The response details are essential for
downstream processing and handling within client applications, making it a
central component for applications utilizing ChatMotor's image processing
capabilities.
The response object includes:
- A status flag indicating if the request was
A list of
MotorImageContainer
objects, each containing an image URL or a base64 string of the generated image, depending on the specified response format in the request. - A
Throwable
object capturing any unexpected exceptions that were thrown.
// Execute the image request.
MotorImageResponse motorImageResponse = motorImageRequest.execute();
if (motorImageResponse.isResponseOk()) {
List<MotorImageContainer> motorImageContainers = motorImageResponse.getImageContainer();
for (MotorImageContainer motorImageContainer : motorImageContainers) {
System.out.println(motorImageContainer.getUrl());
}
System.out.println();
} else {
OpenAiError openAiError = motorImageResponse.getOpenAiError();
OpenAiErrorType errorType = openAiError.getType();
if (errorType != OpenAiErrorType.NO_OPENAI_ERROR) {
System.out.println("OpenAI has returned an error : " + openAiError);
// Take specific action depending on the error code:
if (errorType.equals(OpenAiErrorType.SERVER_ERROR)) {
// ...
} else if (errorType.equals(OpenAiErrorType.TOKENS)) {
// ...
} else {
// Etc.
}
} else {
System.out.println("throwable: " + motorImageResponse.getThrowable());
}
}
This class is vital for interpreting the outcomes of AI-driven image
generation tasks and provides mechanisms to effectively manage and utilize
the results or handle errors and exceptions that may arise during the
process.-
Constructor Summary
Constructors Constructor Description MotorImageResponse()
-
Method Summary
Modifier and Type Method Description List<MotorImageContainer>
getImageContainer()
Gets the list ofMotorImageContainer
objects, each containing an image URL or a baseOpenAiError
getOpenAiError()
Gets the OpenAI error associated with the response.Throwable
getThrowable()
Gets the throwable associated with the response.boolean
isResponseOk()
says whether the response was successful or not.String
toString()
Provides a string representation of this object.
-
Constructor Details
-
MotorImageResponse
public MotorImageResponse()
-
-
Method Details
-
isResponseOk
public boolean isResponseOk()says whether the response was successful or not.- Returns:
- true if the response was successful, false otherwise.
-
getImageContainer
Gets the list ofMotorImageContainer
objects, each containing an image URL or a base- Returns:
- the list of
-
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.
-