Package com.chatmotorapi.api.functional
Class MotorSummaryRequest
java.lang.Object
com.chatmotorapi.api.functional.MotorSummaryRequest
public class MotorSummaryRequest extends Object
Handles the creation and execution of summarization requests using the
ChatMotor
API. This class is designed to summarize text documents
using OpenAI's advanced summarization models configured through the
ChatMotor
. It includes configuration for the text file to be The
model to be used in requests can be specified with the .aiModel setter
directly on the MotorSummaryRequest builder. If .aiModel is not called,
the default model used is System.getenv("MOTOR_CHAT_MODEL"). If the
environment variable is not set, the model used is
MotorDefaultsModels.MOTOR_CHAT_MODEL
Usage example:
String documentPath = "/path/to/my_document.txt";
// We assume that the env var MOTOR_API_KEY is set.
ChatMotor chatMotor = ChatMotor.builder().build();
MotorSummaryRequest request = MotorSummaryRequest.builder()
.chatMotor(chatMotor)
.file(documentFile)
.filePath(documentPath)
.languageCode("fr")
.build();
MotorResponse motorResponse = request.execute();
if (motorResponse.isResponseOk()) {
System.out.println(motorResponse.getResponse());
} else {
// Treat errors
// See the MotorResponse
class for more details.
}
This class uses a builder pattern to ensure a flexible and secure way to configure each summarization request.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MotorSummaryRequest.Builder
Builder class forMotorSummaryRequest
. -
Method Summary
Modifier and Type Method Description String
aiModel()
Gets the AI model to be used in the request.MotorAiOptions
aiOptions()
Gets the AI options to be used in the request.static MotorSummaryRequest.Builder
builder()
Returns a new builder instance for creating aMotorSummaryRequest
.ChatMotor
chatMotor()
Gets the ChatMotor to be used in the request.MotorResponse
execute()
Executes the process of generating a summary from a specified file using a GPT model.MotorStreamStatus
executeAsStream(MotorResponseListener motorResponseListener)
Executes the process of generating a summary from a specified file using a GPT model.String
filePath()
Gets the file path to be used in the request.String
languageCode()
Gets the language code to be used in the request.
-
Method Details
-
chatMotor
Gets the ChatMotor to be used in the request.- Returns:
- the
-
aiOptions
Gets the AI options to be used in the request.- Returns:
- the AI options to be used in the request
-
aiModel
Gets the AI model to be used in the request.- Returns:
- the AI model to be used in the request
-
filePath
Gets the file path to be used in the request.- Returns:
- the file path to be used in the request
-
languageCode
Gets the language code to be used in the request.- Returns:
- the language code to be used in the request
-
builder
Returns a new builder instance for creating aMotorSummaryRequest
.- Returns:
- a new
MotorSummaryRequest
builder
-
execute
Executes the process of generating a summary from a specified file using a GPT model. This method initializes a session with necessary configurations, reads the text file, and creates a summary based on the text content.Workflow:
- Reads the text content from a file.
- Returns a
MotorResponse
indicating success or failure, along with any generated data file or errors.
- Returns:
- true the MotorResponse object
- See Also:
MotorResponse
-
executeAsStream
Executes the process of generating a summary from a specified file using a GPT model.
The configured request is executed as a stream.
This is valid only of request with less that 3000 words- 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.
-