Class MotorExtractContentRequest

java.lang.Object
com.chatmotorapi.api.experimental.MotorExtractContentRequest

public class MotorExtractContentRequest
extends Object
Handles the creation and execution of a content extraction request using the ChatMotor API. This API filters the input text to remove or alter content related to specified topics or keywords, enhancing text sanitization and customization. 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 MotorFilterContentRequest 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.html";
 String responseFile = "/path/to/response_file.html";
 
 // We assume that the env var MOTOR_API_KEY is set.
 ChatMotor chatMotor = ChatMotor.builder().build();
 
 List<String> topics = new ArrayList<String>();
 topics.add("AI Generative);
 topics.add("Machine learning);
         
 MotorExtractContentRequest extractContentRequest = MotorExtractContentRequest.builder()
        .chatMotor(chatMotor)
        .topics(topics)
        .filePath(documentPath)
        .languageCode("fr")
        .build();
 
 MotorResponse motorResponse = extractContentRequest.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 translation request.

  • Method Details

    • builder

      public static MotorExtractContentRequest.Builder builder()
      Returns a new builder instance for creating a MotorExtractContentRequest.
      Returns:
      a new MotorExtractContentRequest builder
    • chatMotor

      public ChatMotor chatMotor()
      Gets the ChatMotor to be used in the request.
      Returns:
      the
    • 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
    • filePath

      public String filePath()
      Gets the file path to be used in the request.
      Returns:
      the file path to be used in the request
    • languageCode

      public String languageCode()
      Gets the language code to be used in the request for content extraction.
      Returns:
      the language code to be used in the request for content extraction
    • topics

      public List<String> topics()
      Gets the topics to be used in the request for content extraction.
      Returns:
      the topics to be used in the request for content extraction
    • execute

      public MotorResponse execute() throws MotorExecutionException
      Executes the process of extracting 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.
      Returns:
      the MotorResponse instance.
      Throws:
      MotorExecutionException - if there is an error reading the file.
    • executeAsStream

      public MotorStreamStatus executeAsStream​(MotorResponseListener motorResponseListener)
      Executes the process of extractting a cotnet from a specified file using a GPT model.
      The configured request is executed as a stream.
      This is valid only of request with a text format 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.