Class MotorFilterContentRequest

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

public class MotorFilterContentRequest
extends Object
Handles the creation and execution of a filer 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(MotorDefaultContentFilters.COMMERCIAL_CONTENT);
 topics.add(MotorDefaultContentFilters.PROFANITY);
 
 MotorFilterContentRequest filterContentRequest = MotorFilterContentRequest.builder()
        .chatMotor(chatMotor)
        .filePath(documentPath)
  *     .topics(topics)
        .languageCode("fr")
        .build();
 
 MotorResponse motorResponse = filterContentRequest.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 MotorFilterContentRequest.Builder builder()
      Returns a new builder instance for creating a MotorFilterContentRequest.
      Returns:
      a new MotorFilterContentRequest 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 filter.
      Returns:
      the language code to be used in the request for content filter.
    • topics

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

      public MotorResponse execute() throws MotorExecutionException
      Executes the process of generating a translation 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 generating a filtering 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.