Package com.chatmotorapi.api.vision
Class MotorVisionRequest
java.lang.Object
com.chatmotorapi.api.vision.MotorVisionRequest
public class MotorVisionRequest extends Object
Handles the creation and execution of Vision requests to the ChatMotor using system and user prompts.
This class uses the Builder pattern to ensure flexibility and enforce mandatory configuration.
The model to be used in requests can be specified with the .aiModel setter directly on the
MotorSpeechRequest builder.
If .aiModel is not called, the default model used is System.getenv("MOTOR_VISION_MODEL"). If the environment variable is not set, the model used is
Note that the API supports streaming requests.
If .aiModel is not called, the default model used is System.getenv("MOTOR_VISION_MODEL"). If the environment variable is not set, the model used is
MotorDefaultsModels.MOTOR_VISION_MODEL
. Note that the API supports streaming requests.
Usage example:
// We assume that the env var MOTOR_API_KEY is set
// Create a ChatMotor instance.
ChatMotor chatMotor = ChatMotor.builder().build();
// Optionally build a MotorAiOptions instance.
MotorAiOptions options = MotorAiOptions.builder()
.temperature(0.7)
.maxTokens(1000)
.build();
String text = "Describe what you see in this image.";
String imageUrl = "https://upload.wikimedia.org/wikipedia/commons/d/d1/"
+ "Mount_Everest_as_seen_from_Drukair2_PLW_edit.jpg";
MotorContentPartText motorContentPartText = new MotorContentPartText(text);
MotorContentPartImage motorContentPartImage = new MotorContentPartImage(
imageUrl);
// Build a Vision request
MotorVisionRequest visionRequest = MotorVisionRequest.builder()
.chatMotor(chatMotor)
.motorAiOptions(options)
.contentPartText(motorContentPartText)
.contentPartImage(motorContentPartImage)
.build();
// Execute the request.
MotorResponse motorResponse = visionRequest.execute();
if (motorResponse.isResponseOk()) {
String response = motorResponse.getResponse();
System.out.println(response);
}
else {
// Treat errors
// See the MotorResponse
class for more details.
}
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MotorVisionRequest.Builder
Builder class for creating a MotorVisionRequest instance. -
Method Summary
Modifier and Type Method Description static MotorVisionRequest.Builder
builder()
Returns a new instance ofMotorVisionRequest.Builder
, which is used to construct aMotorVisionRequest
object.MotorResponse
execute()
Executes the chat request using the configured settings and messages.MotorStreamStatus
executeAsStream(MotorResponseListener motorResponseListener)
Executes the configured request as a stream and returns the execution status.String
getOpenAiModel()
Gets the OpenAI model for the Request.
-
Method Details
-
getOpenAiModel
Gets the OpenAI model for the Request.- Returns:
- the OpenAI model
-
builder
Returns a new instance ofMotorVisionRequest.Builder
, which is used to construct aMotorVisionRequest
object.- Returns:
- a new instance of
MotorVisionRequest.Builder
for creatingMotorVisionRequest
objects.
-
execute
Executes the chat request using the configured settings and messages.
This method processes the accumulated settings and messages to interact with the ChatMotor, ultimately generating a response based on the user and system prompts provided.- Returns:
- A new
MotorImageResponse
object containing the results of the request execution.
-
executeAsStream
Executes the configured request as a stream and returns the execution status.- Parameters:
motorResponseListener
- The listener that will handle the streamed data chunks.- Returns:
- An instance of
MotorStreamStatus
that contains information about the outcome of the streaming operation.
-