User Guide
ChatMotor API v1.2-beta - September 20, 2024
The ChatMotor API allows seamless integration of ChatGPT capabilities into your Java applications, focusing on what you want to achieve without the need to manage complex implementation details.
What's New
Check out our Changelog.
Credits and Acknowledgments
ChatMotor is built on top of the open-source Simple-OpenAI Java SDK developed by Sashir Estela and peers.
We extend our gratitude for their work, which has been fundamental to the development of ChatMotor.
Introduction to ChatMotor
ChatMotor is an advanced Java SDK designed for integrating with the ChatGPT API, providing a comprehensive and robust set of features. Built on the solid foundation provided by Simple-OpenAI, ChatMotor not only enhances several of the base SDK's capabilities but also introduces a range of unique features tailored to extend functionality and improve user experience:
Enhanced Streaming: Simplified management of streaming for progressive teletext display.
Automatic Retry Mechanism: Abstracted HTTP management for reliable API calls.
Customizable Timeouts: Easy setup for timeouts tailored to your needs.
Proxy Support: Seamless integration of proxy information.
Unlimited Input Prompt Size: Automatic sequencing for prompts exceeding 4096 tokens.
Advanced Summarization: Summarization & strategic summarization.
Advanced Translation: No input size limits with preservation of original formatting.
Advanced Functional APIs: Categorization, Entity Recognition, Sentiment Analysis.
Consistent API Calls: Easy to memorize and use with consistent method names for all operations, such as
execute()
,executeAsStream()
, etc.Unlimited Audio Transcription: Bypass OpenAI's 25 MB limit.
Text-to-Speech API: Unlimited input size for converting text to audio.
Functional APIs: For summarization, strategic summaries, content extraction, and filtering. Includes now entity recognition, categorization and sentiment analysis.
Comprehensive Format Management: Support for various input/output formats including txt, RTF, Word, HTML, PDF.
Vision and DALL-E Integration: Generate text from images and images from text.
Large File Processing: Large files are processed in parallel by splitting them into chunks and handling each chunk with separate simultaneous threads for faster processing.
Default Settings for Easy Start and Testing: Pre-configured defaults that facilitate immediate usage and testing without initial setup.
Optional Environment Variable Configuration: Configuration via environment variables reduces code, simplifies complexity, and enhances maintainability in applications developed using ChatMotor.
Failover Key Mechanism: Provides a robust backup strategy, ensuring continuous service availability and reliability by automatically switching to a secondary OpenAI key if the primary account fails (Quota limits, CB date expired, ...).
No Exceptions Thrown: ChatMotor requests don't throw exceptions, making it easy to manage errors without disrupting your application's flow.
Detailed Error Messages: We decode OpenAI error messages, providing comprehensive details for effective troubleshooting.
No Null Values Returned: We ensure that methods never return null values, providing default values to maintain predictable and robust behavior. It's time in 2024 to make an end to the 1 billion dollars mistake.
Complete Javadoc and Code Examples
ChatMotor's extensive Javadoc and sample code ensure that you have all the tools necessary for seamless integration. Each class is accompanied by a complete how-to guide embedded within the Javadoc, along with ready-to-work code examples.
This detailed Javadoc ensures that developers can access all necessary information for effective integration and utilization of the SDK, even without the user guide.
Download the Software
Download the installation file from ChatMotor Download.
Choosing your Edition
When downloading, you have automatically access to Pro Edition for 30 days, then ChatMotor will reverse to Free Edition
Feature
Free Edition
Pro Edition
Integration with OpenAI API
Yes
Yes
Base Requests & Functional APIs (Translation, Summary)
Limited (Up to 50,000 characters text files and 250KB HTML files)
Unlimited
Audio Files Transcription
Up to 1 hour duration
Unlimited
Text to Audio
Up to 50,000 characters
Unlimited
Token Usage Visibility
Basic (Total tokens only)
Detailed (Prompt, Completion, and Total tokens)
HTTP Proxy Support
Yes, without authentication
Yes, with authentication
Advanced Functional APIs (Categorization, Entity Recognition, Sentiment Analysis)
No
Yes
Post-Processing Notification API (SMS, Slack, Email)
No
Yes
Failover OpenAI API Key
No
Yes
Email Support
Best Effort
Priority Support
Access to All Functional APIs for 30-Day Trial
Yes
N/A
Upgrades and New Versions
No
Yes, with annual maintenance fee
Requirements
ChatMotor API requires Java 11 or higher and is compatible with Windows, macOS, Linux, and Android.
Transcribing files in formats other than MP3 requires FFMPEG to be installed on Linux and macOS.
On Android, only MP3 file transcription is supported.
Installation Details
Extract the downloaded
chatmotor-api-1.2-beta.zip
archive to a directory, such as/path/to/software
.Set the
CHATMOTOR_HOME
environment variable to the installation directory:- Add the
CHATMOTOR_HOME/lib
directory to your development environment'sCLASSPATH
.When deploying in production, include all JAR files from the
/lib
directory in theCLASSPATH
.For J2EE Web servers: Copy the contents of the
CHATMOTOR_HOME/lib
directory to the server'slib
directory while preserving the installation files.
Example
If the zip
file is extracted to /home/user1
, the directory structure will be /home/user1/chatmotor-api-1.2-beta
. Set CHATMOTOR_HOME
in your bash settings file as follows:
Android
Since Android does not support environment variables, you will need to explicitly set the ChatMotor home directory using the ChatMotor.setChatMotorHome(String chatMotorHome)
method:
Add the following three lines to your AndroidManifest.xml
:
Purchasing the Pro Edition
If you choose to purchase the Pro Edition after the 30-day trial, visit our Pricing Page for more information and purchasing options.
At the end of the trial, the software will automatically revert to the Free Edition if not purchased. After purchasing, you’ll receive a license file via email. No need to reinstall—just place the license file in:
Where CHATMOTOR_HOME
is either the environment variable CHATMOTOR_HOME
or the value defined by the ChatMotor.setChatMotorHome(String chatMotorHome)
method.
Getting Started
Creating a ChatMotor Object
Here is the initial step required to use the services: you must create a ChatMotor instance and pass to it the license file path and the OpenAI key:
In this example, replace "your_openai_api_key"
with your actual API key. This code initializes the ChatMotorClient
with the API key, enabling you to make authenticated requests.
Alternatively, you may set the OpenAI keey using the environment variables CHATMOTOR_API_KEY
:
For example, this could be your settings:
Defining OpenAI options
The AI options (temperature, max tokens, etc.) are optionally defined with the MotorAiOptions class:
See the MotorAiOptions class Javadoc all options and the corresponding default values.
Making a Chat Completion Request
After creating the ChatMotor instance, and optionally a MotorAiOptions instance he you can start making requests to various endpoints provided by the ChatMotor SDK.
Here's an example of how to call the Chat Completion service to ask a question and wait for a complete answer. The response is printed to the console. This is a simple request, functioning exactly as it does when using ChatGPT in your browser. It uses 2 classes: MotorRequest for the request creation, and MotorResponse to manage the response.
The OpenAI model in use is defined in
Exception Management
To make the developer's life easier, the MotorRequest
and all other API requests provided by the ChatMotor SDK are designed to never throw exceptions. Instead, they use a status-checking mechanism that simplifies error handling and improves code readability:
No Need for Try-Catch Blocks:
Developers do not need to wrap their API calls in try-catch blocks, resulting in cleaner and shorter code.
Consistent Error Checking:
By using a consistent method to check for errors, developers can easily manage error handling across different parts of their application.
Consistent Request and Response Handling
All our requests and responses are designed to be consistent and never throw exceptions.
Developers can simply check the response status using isResponseOk()
to determine if the request was successful and use getThrowable()
to retrieve any exceptions. This approach ensures unified and predictable error management, leading to more reliable and maintainable code.
Unchecked Exceptions
To provide immediate understanding of certain errors, we have a few unchecked exceptions that can be accessed via MotorResponse.getThrowable()
. These exceptions help developers quickly identify specific issues without the need for extensive debugging:
MotorExecutionException:
Indicates that an error occurred during the execution of the request. This exception helps pinpoint issues that arise during the processing phase.
MotorNotImplementedException:
Indicates that a requested feature or function is not implemented. This exception is useful for identifying missing functionality and ensuring that developers are aware of unimplemented features.
MotorTimeoutException:
Indicates that the request timed out. This exception helps developers understand that the operation took too long and was aborted due to a timeout.
By using these unchecked exceptions, developers can quickly understand and address common errors, improving the development experience and reducing the time spent on troubleshooting.
Extracting OpenAI Errors
Handling OpenAI errors effectively is crucial for robust application development. ChatMotor provides mechanisms to extract and manage OpenAI errors efficiently.
Example of Extracting OpenAI Errors
When executing a request, you can check if the response contains an OpenAI error and extract the error details as follows:
See the OpenAiError Javadoc.
Making a Chat Completion Request with Streaming Response
The executeAsStream method allows you to benefit from ChatGPT's streaming capabilities, enabling the response to be processed and displayed in real-time. This method is particularly useful when you want to provide immediate feedback to the user as the response is being generated, rather than waiting for the entire response to be completed.
Explaining the MotorResponseListener interface
The MotorResponseListener interface allows you to handle responses from the ChatMotor service in real-time as they are being streamed. Implementing this interface enables you to process each part of the response immediately, which is useful for providing instant feedback to users.
Advantages of Using a Listener
Avoids Async Methods: The listener mechanism eliminates the need for complex asynchronous methods, simplifying the code.
Immediate Processing: Each part of the response is processed as soon as it is received, providing real-time interaction and feedback.
Using the MotorResponseListener
, developers can easily handle streaming responses, improving user experience with real-time updates and reducing the complexity of asynchronous programming.
Example Implementation: ConsoleResponseListener
Here's an example implementation of the MotorResponseListener
that prints the response to the console as it is received:
We provide also other standard ready to use implementation : QueueResponseListener, MotorFileResponseListener and SwingResponseListener which are described in their Javadoc.
Keeping the Context in the Conversation
By adding UserMessages
to the list in a loop and executing the motorRequest.execute()
method, you can maintain the context of the conversation, just as you would in a browser session. Here's an example demonstrating how to do this in the context of building a Java method:
This will display the following flow in the console.
Advanced Topics
File
The ChatMotor APIs are designed to handle input text files, defined by their extensions (txt, text, csv, or their uppercase equivalents). This means that the .filepath(String filepath)
method of all APIs (except MotorLargeTranslationRequest
see below) accepts only text files. This restriction is due to the nature of OpenAI APIs, which take text content as input and return text content without formatting options.
Supported Text File Extensions (Case-Insensitive)
.txt
.text
.csv
FileToTextConverter Utility
For other formatted files, we provide a utility called FileToTextConverter
that allows extracting text from the following file types based on their (case-insensitive) extensions and dumping content in a text file:
.html
.csv
.doc
.docx
.rtf
Example:
Exception: Translation APIs support HTML files
The MotorLargeTranslationRequest
API also accepts HTML input. This API will return the same formatted HTML file with its content translated.
Large Content Management: MotorLargeRequestLine
The MotorLargeRequestLine class facilitates creating and executing large-sized requests for the ChatMotor API. It uses a builder pattern for flexible and reliable configuration, handling large input by submitting consecutive standard-sized requests and aggregating responses into a final comprehensive result.
Isomorphic Transformations
This class is designed for isomorphic tasks like translation and CSV manipulation, where each chunk of user prompts can be processed independently and then combined. It is ideal for scenarios requiring the transmission of huge data volumes efficiently.
Line-Based File Processing
The input file for MotorLargeRequestLine
must contain lines of text, as it processes the content line by line. This approach ensures smooth handling of large files without exceeding token limits.
Streaming Processing
MotorLargeRequestLine
processes large content using streaming, allowing it to handle very large-sized files efficiently. By processing the file line by line, it submits consecutive requests and aggregates the results, ensuring that even enormous data volumes are managed effectively without hitting token limits.
Chunk Input Size
It is optionally possible to set the chunk input size with MotorLargeRequestLine.inputChunkSizeBytes(int inputChunkSizeBytes)
. This is not recommended.
Since we are doing isomorphic transformations, the chunk input size must be less than 4096 tokens, corresponding to the OpenAI maximum response size. The default value for inputChunkSizeBytes
is retrieved from the current ChatMotor
instance using chatMotor.maxChunkInputSize()
, which ensures a conservative size to prevent data loss.
inputChunkSizeBytes
cannot exceed ChatMotor.maxChunkInputSize()
.
This default size avoids data loss during transformation by ensuring the output size does not exceed the model's maximum token limit.
Usage Example
Here's how you can use MotorLargeRequestLine
to process a large CSV file:
Explanation
Initialization: The
MotorLargeRequestLine
is built with the ChatMotor instance, AI options, system message, and the path to the input file.Streaming Processing: Processes the file line by line using streaming, ensuring efficient handling of very large files.
Chunk Input Size: Optionally set the chunk input size, ensuring it is less than 4096 tokens.
Execution: The
execute()
method processes the large content and aggregates the responses.Error Handling: Checks if the response contains an OpenAI error and handles it accordingly, or outputs any exceptions.
This approach ensures efficient handling of large content, making it ideal for scenarios requiring the processing of extensive data volumes.
Large Content Management: MotorLargeRequestText
The MotorLargeRequestText class facilitates the creation and execution of large-sized requests for the ChatMotor API using a builder pattern for flexible and reliable configuration. It is ideal for scenarios requiring the transmission of large volumes of unstructured text, such as books and reports. This class handles large input by splitting it into smaller chunks, submitting them consecutively to the ChatMotor, and aggregating individual responses into a final comprehensive result.
Input Size
This example processes a large, unstructured text by splitting it into complete sentences and applying the same query to each portion. The input file will be divided into multiple chunks submitted to the ChatGPT API, meaning context will be lost between each request and response due to the context size restrictions of the ChatMotor API.
GPT-4 Turbo, for example, has a context window of 128k tokens and a maximum response size of 4096 tokens. Each response is dedicated to a specific portion of the text because we cannot produce a response that exceeds 4096 tokens.
You can define a chunk size using the MotorLargeRequestText.inputChunkSizeBytes
method. This is not recommended.
The default value for inputChunkSizeBytes
is retrieved from the current ChatMotor
instance using chatMotor.maxInputSize()
, which is set to 440KB. This size is suitable for GPT-4 models.
inputChunkSizeBytes
cannot exceed the value defined by ChatMotor.maxInputSize()
.
Usage Example
Check the input text at: proust-chapter-1.txt Check the response produced at: proust-chapter-1-response.txt
Automatic Retry Mechanism
ChatMotor ensures robust and reliable communication by handling HTTP requests automatically and offering a retry functionality with capping and delay management. This reduces the likelihood of errors disrupting operations.
Usage Example
Timeout Setup
ChatMotor allows you to set a timeout for API requests to ensure efficient resource management and prevent indefinite blocking, maintaining the responsiveness of your application.
Usage Example
Proxy Configuration
ChatMotor allows you to configure a proxy for API requests, enabling you to manage network traffic effectively and ensure secure and controlled communication.
Usage Example
Failover Mechanism
If your account exceeds its quota or hits the rate limit, ChatMotor ensures continuity with a failover mechanism. A secondary OpenAI key linked to a secondary account will be used automatically if the primary account fails.
Usage Example
Audio and Image APIs
Transcription
ChatMotor handles the creation and execution of transcription requests using the OpenAI Whisper model. The MotorTranscriptionRequest class is designed to transcribe audio files into text with unlimited size, bypassing the 25MB OpenAI Whisper limitation.
Large files are chunked to reduce memory consumption. The default chunk size is 4MB, but this can be overridden
Key Features
FFmpeg: Required to install on Linux and macOS to handle media processing.
Unlimited Size: Transcription size is not bound to the 25MB OpenAI Whisper limitation.
Memory Optimization: Large files are chunked to reduce memory consumption.
Flexible Configuration: Uses a builder pattern for secure and flexible configuration.
Model Specification: The model can be specified with the
.aiModel
setter on theMotorTranscriptionRequest
builder. If not set, it defaults to the model specified in theMOTOR_WHISPER_MODEL
environment variable orMotorDefaultsModels.MOTOR_WHISPER_MODEL
.Format Conversion: Large files in formats other than MP3 are converted to MP3 for better chunk quality.
ffmpeg Its required to install ffmpeg on Linux and macOS.
The MotorTranscriptionRequest class
The MotorTranscriptFormatterRequest class
The MotorTranscriptFormatterRequest class allows you to format a transcription file using line breaks and paragraphs. It ensures that the transcribed text is readable and well-structured.
Usage Example
Speech
The MotorSpeechRequest API handles the creation and execution of text-to-speech requests to the ChatMotor using user prompts. It employs the builder pattern to ensure flexibility and enforce mandatory configuration. The model used in requests can be specified with the .aiModel
setter on the MotorSpeechRequest
builder. If not set, it defaults to the model specified in the MOTOR_SPEECH_MODEL
environment variable or MotorDefaultsModels.MOTOR_SPEECH_MODEL
.
Key Features
Model Specification: The model can be set using the
.aiModel
setter or defaults to the environment variableMOTOR_SPEECH_MODEL
.Input Limits: Standard requests are limited to 500 words for non-MP3 files. There are no limits for MP3 files.
Audio File Conversion: Use
MotorAudioFileConverter
to convert audio files to MP3 and vice versa.
Usage Example
Image
The MotorImageRequest API handles the creation and execution of image-related requests for the ChatMotor API, designed to interface with OpenAI's Vision API. This class leverages the builder pattern to provide a flexible and reliable configuration mechanism, ensuring that all necessary parameters are set before execution.
Key Features
Model Specification: The model can be set using the
.aiModel
setter or defaults to the environment variableMOTOR_IMAGE_MODEL
.Input Limits: Image requests are limited to 4096 tokens.
Usage Example
Vision
The MotorVisionRequest API handles the creation and execution of vision-related requests to the ChatMotor using system and user prompts. This class uses the builder pattern to ensure flexibility and enforce mandatory configuration.
Key Features
Model Specification: The model can be set using the
.aiModel
setter or defaults to the environment variableMOTOR_VISION_MODEL
.Streaming Support: The API supports streaming requests for efficient processing.
Usage Example
Usage Example with a local image
MotorVisionRequest
also supports using a local image loaded with VisionImageUtil.
Functional APIs
The Functional APIs in ChatMotor provide advanced text processing capabilities tailored to tasks like summarization and translation. These APIs offer higher-level functionality and do not directly wrap OpenAI or underlying Sample-OpenAI APIs. Instead, they leverage these models to provide specialized features, enabling developers to handle complex text operations more effectively and efficiently.
Summarization
Classic Summary
The Classic Summary API generates a concise overview of the input text, capturing the main points while reducing the text to a shorter form.
The MotorSummaryRequest class handles the creation and execution of summarization requests. It allows configuration for the text file to be summarized and the model to be used. If the model is not specified, it defaults to the value set in the MOTOR_CHAT_MODEL
environment variable or MotorDefaultsModels.MOTOR_CHAT_MODEL
.
Key Features:
Flexible Configuration: Uses a builder pattern for secure and customizable request configuration.
Model Specification: The model can be set via the
.aiModel
method or defaults to environment variables.Language Specification: The language of the text must be specified to ensure accurate summarization, as ChatGPT may mix up languages. In automation flows, the
MotorLanguageGuesserRequest
class can be used to reliably detect the language of the text.Text Format Support: Only text formats are supported because OpenAI understands only text formats. This includes file types like
.txt
,.csv
, and.text
.Line Feed Preservation: The API tries to preserve the line feeds of the passed text, except for the streaming "teletype" response of OpenAI (
executeAsStream
method).File Conversion: For other formats, the
FileToTextConverter
class allows converting most current formats (e.g.,.html
,.docx
,.pdf
) to text.In-Memory Summarization: Summaries are treated as text in memory because summarization is not an isomorphic 1-to-1 operation and there is no reliable way to handle large files due to context loss between parts. The summary will thus be a maximum (for GPT-4 models) of 124KB tokens input and 4096 tokens output.
Usage Example:
Strategic Summary
The MotorStrategicSummaryRequest API offers the same key features as the Classic Summary but focuses on providing a high-level synthesis of the given text, extracting the most critical information and key insights. The output is always in HTML format, enhancing key points for better readability and understanding.
A strategic summary is designed to provide a quick understanding of the main points, trends, and actionable items within the text, making it ideal for decision-making processes and strategic planning.
Key Features:
Concise Overview: Summarizes the text to highlight essential information.
Key Insights: Focuses on the main points, trends, and actionable items.
Decision Support: Aids in strategic planning and decision-making by providing a quick understanding of the content.
The response will be in HTML format to guarantee readability and ease of understanding. There is no executeAsStream
method implemented in this class.
Usage Example:
Translation
Large Files Translation
The MotorLargeTranslationRequest API (handles the translation of text files, whether small or extensive. It preserves the format and structure of the original content while providing high-quality translations. This API uses streaming from input to output, preventing high memory consumption and ensuring efficient handling of large inputs. Users don't need to consider the size of their files; the API automatically switches modes to handle the file efficiently.
ChatMotor will automatically handle the buffer size to ensure no loss of data, but you can always fine-tune the default value of the input buffer length.
This class ensures the format is preserved when translating an HTML file. This allows you to convert Word files to HTML, process them for translation, and then reintegrate them back into Word easily by using "Open With" on the HTML file.
Web Services for PDF or Word to HTML Conversion
To facilitate automated processing, we will offer a free web service in the next ChatMotor beta version to convert Word files to HTML and HTML files to Word. This service will leverage the latest market technology for HTML to Word conversion. We are not experts in file conversion and do not intend to become one, but we aim to provide a useful tool within the current technological limits.
Usage Example:
When setting up the MotorLargeTranslationRequest
, you can choose between two implementations for handling large translation requests:
Input Streaming: If
useInputStreaming
is set totrue
, the streaming implementation using SAX Parser and TagSoup is used. This method is more efficient for large files, as it processes data in a stream, reducing memory consumption. However, it may be less robust in this beta version.In-Memory Processing: If
useInputStreaming
is set tofalse
(default), the Jsoup implementation is used, which loads files entirely into memory before processing. This approach is simpler and more reliable but can be less efficient for very large files.
Other Experimental Functional APIs
As part of our continuous innovation, we are introducing experimental APIs designed to enhance text sanitization and customization. Please note that these APIs are in the experimental phase, and response times may vary.
Content Extraction
The MotorExtractContentRequest API enables you to filter the input text to remove or alter content related to specified topics or keywords. This API enhances text sanitization and customization, making it easier to tailor content to specific needs.
Usage Example:
Content Filtering
The MotorFilterContentRequest API allows you to filter the input text to remove or alter content related to specified topics or keywords. This API enhances text sanitization and customization, making it easier to ensure that your content adheres to certain standards or guidelines.
Usage Example:
Note on Experimental APIs
These APIs are currently in an experimental phase, and while they offer powerful capabilities for content extraction and filtering, their response times may not always be optimal. We are actively working to enhance their performance and reliability. Your feedback is valuable to us as we continue to improve these features.
Pro Supplemental APIs
ChatMotor provides advanced supplemental APIs for specialized text processing tasks. These APIs include MotorCategorizationRequest
, MotorEntityRequest
, and MotorSentimentRequest
, each tailored for specific use cases such as categorization, entity extraction, and sentiment analysis.
Categorization (MotorCategorizationRequest)
The MotorCategorizationRequest API is designed for categorizing text into predefined or custom categories. It is useful for tasks like content tagging, spam filtering, or topic detection.
Usage Example:
See the MotorCategorizationResponse Javadoc for response details.
Entity Extraction
The MotorEntityRequest
API extracts named entities such as people, locations, and organizations from a text. This is useful for processing articles, reports, or emails to extract structured data.
Usage Example:
See the MotorEntityResponse Javadoc for response details.
Sentiment Analysis
The MotorSentimentRequest
API analyzes the sentiment of a given text, identifying whether the sentiment is positive, negative, or neutral. It is useful for customer feedback analysis, social media monitoring, and more.
Usage Example:
See the MotorSentimentResponse Javadoc for response details.
Notification API
The Notification API in ChatMotor allows you to notify users that their document is ready or send the document to them directly after an AI request is processed. This is especially useful for scenarios where users may be waiting for a document to be generated and need to be informed promptly. It supports multiple communication channels, including SMS (via Twilio), Slack, and Email.
The API is designed to be flexible and extendable, allowing new communication channels to be added easily, such as Notion or Airtable, in addition to the built-in implementations.
Key Features
Notify Users: Inform users as soon as their document is ready for download or review.
Send Documents: Dispatch the processed document to the user through various communication channels.
Extendable: Easily add new notification channels by implementing the
NotificationChannel
interface.Synchronous/Asynchronous Execution: Choose between synchronous (SYNC) and asynchronous (ASYNC) execution modes for notifications and document dispatch.
NotificationChannel Interface
The NotificationChannel interface defines two key methods:
notifyDocumentAvailable()
: Notifies the user that a response document is available.dispatchDocument()
: Sends the document to the user.
Both methods accept the document's file path and the execution mode (SYNC
or ASYNC
).
MotorNotifyResponse
The MotorNotifyResponse indicates whether the notification and/or send operation was successfully delivered. Note that this response is meaningful only in SYNC
mode.
Example Usage: Slack Notification
The following example demonstrates how to use the Slack implementation to notify users and send a document.
Other Implementations
You can also use other communication channels, such as:
SMS (via Twilio): Notify users via SMS using Twilio with the TwilioNotificationChannel implementation.
Email: Send email notifications or dispatch documents directly to a user's inbox using the EmailNotificationChannel implementation.
Extendable Design
The Notification API is designed to be flexible and extensible. You can create custom implementations for other platforms by implementing the NotificationChannel
interface. This allows you to use any communication service (e.g., Notion, Airtable, or internal company systems) to notify users or send documents.
Troubleshooting and Best Practices
Common Issues and Solutions
API Key Issues
Problem: Invalid or missing API key.
Solution: Ensure that your API key is correctly set in the environment variables
MOTOR_API_KEY
. Verify that the key has the necessary permissions.
License File Issues
Problem: License file not found or invalid.
Solution: Make sure the
MOTOR_LICENSE_FILE_PATH
environment variable points to the correct path of your license file. Verify the contents and validity of the license file.
Network Issues
Problem: Network connectivity problems causing request failures.
Solution: Verify your network connection. If using a proxy, ensure it is correctly configured in your
ChatMotor
setup.
Performance Issues
Problem: high memory consumption with
MotorLargeTranslationRequest
APISolution: Optimize your request parameters and use the streaming options for handling large files efficiently.
Be Patient with Large Requests
When using MotorLargeRequestText
, MotorLargeRequestLine
, or MotorLargeTranslationRequest
, and MotorLargeTranscriptionRequest
, it's important to be patient. These operations can take a significant amount of time, especially for very large files.
Note: Even if a translation or processing takes an hour, it is still far faster and more cost-effective than manual human processing. Understand that large text processing, line processing, and translations are intensive operations. The API handles large files by splitting them into smaller chunks and processing each chunk sequentially. This ensures accurate results but can increase the processing time.
Appendix
Reference to sample code examples
For sample code examples and detailed usage instructions, please refer to the ChatMotor Java Samples project. This repository contains comprehensive examples and guides to help you integrate and utilize the ChatMotor API in your Java applications.
Last updated