Package com.chatmotorapi.api
Class MotorLargeRequestLines
java.lang.Object
com.chatmotorapi.api.MotorLargeRequestLines
public class MotorLargeRequestLines extends Object
Facilitates the creation and execution of large-sized requests for the
ChatMotor API using a builder pattern for flexible and reliable
configuration.
Handles large input by submitting consecutive standard-sized requests to the ChatMotor and aggregating each individual response into a final comprehensive response.
This class is suited for isomorphic tasks like translation, CSV manipulation, etc. where each chunk of user prompts can be processed independently and then combined for a final result.
This class is ideal for scenarios requiring the transmission of huge or enormous data volumes, ensuring efficient handling through the ChatMotor. The model to be used in requests can be specified with the .aiModel setter directly on the
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
You can add a ProgressListener to the request to track progress using
Changing the content of the submitted CSV file and getting a large response.
Handles large input by submitting consecutive standard-sized requests to the ChatMotor and aggregating each individual response into a final comprehensive response.
This class is suited for isomorphic tasks like translation, CSV manipulation, etc. where each chunk of user prompts can be processed independently and then combined for a final result.
This class is ideal for scenarios requiring the transmission of huge or enormous data volumes, ensuring efficient handling through the ChatMotor. The model to be used in requests can be specified with the .aiModel setter directly on the
MotorLargeRequestLines
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
You can add a ProgressListener to the request to track progress using
.progressListener(ProgressListener progressListener)
.
See the User Guide for more info.
Usage Example:
Changing the content of the submitted CSV file and getting a large response.
// Assume that the env var MOTOR_API_KEY are set.
ChatMotor chatMotor = ChatMotor.builder()
.build();
MotorAiOptions options = MotorAiOptions.builder()
.temperature(0.0) // No creativity
.maxTokens(4096) // Max tokens.
.build();
String filePath = "/path/to/user/Fahrenheit.csv";
MotorSystemMessage motorSystemMessage = new MotorSystemMessage(
"I will provide you with temperature measurements in Fahrenheit in a text file. "
+ "Convert the temperatures to degrees Celsius and add ';true' at the end of the line "
+ "if the temperature is above 20 degrees Celsius. "
+ "Do not add any comments and maintain the exact input format "
+ "without adding any new CR/LF characters.");
MotorUserMessage motorUserMessage = new MotorUserMessage(userPrompt);
MotorLargeRequestLines request = MotorLargeRequestLines.builder()
.chatMotor(chatMotor)
.aiOptions(options)
.systemMessage(motorSystemMessage)
.filePath(filePath)
.build();
// Execute the request.
MotorLargeResponse largeResponse = request.execute();
if (largeResponse.isResponseOk()) {
String outFilePath = "/path/to/Celsius.csv";
try (InputStream in = largeResponse.getInputStream();) {
Files.copy(in, Paths.get(outFilePath), StandardCopyOption.REPLACE_EXISTING);
}
}
else {
// We check if the response is an OpenAI error and get the OpenAI error details
// (type and message)
OpenAiError openAiError = largeResponse.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 : " + largeResponse.getThrowable());
}
}
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MotorLargeRequestLines.Builder
Builder class for creating a MotorLargeRequestLines instance. -
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 MotorLargeRequestLines.Builder
builder()
Static method to initiate building a MotorLargeRequestLines instance.ChatMotor
chatMotor()
Gets the ChatMotor to be used in the request.MotorLargeResponse
execute()
Handles large input by submitting consecutive standard-sized requests to the ChatMotor and aggregating each individual response into a final comprehensive response.String
filePath()
Returns the file pathChunkSize
inputChunkSize()
Returns the input chunk sizeProgressListener
progressListener()
Gets the ProgressListener to be used in the request.MotorSystemMessage
systemMessage()
Returns the system prompt
-
Method Details
-
chatMotor
Gets the ChatMotor to be used in the request.- Returns:
- the ChatMotor instance
-
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
-
systemMessage
Returns the system prompt- Returns:
- the system prompt
-
filePath
Returns the file path- Returns:
- the file path
-
inputChunkSize
Returns the input chunk size- Returns:
- the input chunk size
-
progressListener
Gets the ProgressListener to be used in the request.- Returns:
- the ProgressListener instance
-
builder
Static method to initiate building a MotorLargeRequestLines instance.- Returns:
- a new Builder instance
-
execute
Handles large input by submitting consecutive standard-sized requests to the ChatMotor and aggregating each individual response into a final comprehensive response. This method is suited for tasks like translation, where each chunk of user prompts can be processed independently and then combined for a final result.Typical Usage: Used primarily for conversion operations of large content, where each portion of the text can be independently translated and then stitched together.
Examples include:- Translating a large text document into multiple languages. (We provide
the built in
MotorSummaryRequest
API for translating text files and HTML files.) - Converting or adding info in database rows, inputed in a file text line by line, of a huge SQL table.
- Converting or adding info of a large CSV file lines containing scientific measures.
- Returns:
- MotorResponse The aggregated response combining all individual responses from the submitted chunks.
- Translating a large text document into multiple languages. (We provide
the built in
-