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 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());
    }
 } 
 
 
  • Method Details

    • chatMotor

      public ChatMotor chatMotor()
      Gets the ChatMotor to be used in the request.
      Returns:
      the ChatMotor instance
    • aiOptions

      public MotorAiOptions aiOptions()
      Gets the AI options to be used in the request.
      Returns:
      the AI options to be used in the request
    • aiModel

      public String aiModel()
      Gets the AI model to be used in the request.
      Returns:
      the AI model to be used in the request
    • systemMessage

      public MotorSystemMessage systemMessage()
      Returns the system prompt
      Returns:
      the system prompt
    • filePath

      public String filePath()
      Returns the file path
      Returns:
      the file path
    • inputChunkSize

      public ChunkSize inputChunkSize()
      Returns the input chunk size
      Returns:
      the input chunk size
    • progressListener

      public ProgressListener progressListener()
      Gets the ProgressListener to be used in the request.
      Returns:
      the ProgressListener instance
    • builder

      public static MotorLargeRequestLines.Builder builder()
      Static method to initiate building a MotorLargeRequestLines instance.
      Returns:
      a new Builder instance
    • execute

      public MotorLargeResponse 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.