Documentation
Overview
The LLMWhispererClientV2
class is a client for interacting with the version 2 of the LLMWhisperer API. This class provides functionality for making API requests to process files, retrieve usage information, check the status of operations, and manage webhooks.
Environment Variables
Variable | Description |
---|---|
LLMWHISPERER_BASE_URL_V2 | The base URL of the API. When left undefined, default https://llmwhisperer-api.us-central.unstract.com/api/v2 is used |
LLMWHISPERER_API_KEY | The API key to use for authenticating requests to the API. |
LLMWHISPERER_LOGGING_LEVEL | The logging level to use. Possible values are error , warn , info , debug |
All environment variables are optional. If LLMWHISPERER_API_KEY
is not set, you must provide the API key when creating a new client. The environment variables can be overridden by providing the values in the client constructor.
Constructor
LLMWhispererClientV2({ baseUrl = "", apiKey = "", loggingLevel = "" } = {})
Parameters:
- baseUrl (
string
, optional): The base URL of the API. If not provided, the class usesprocess.env.LLMWHISPERER_BASE_URL_V2
or the default URLhttps://llmwhisperer-api.us-central.unstract.com/api/v2
. - apiKey (
string
, optional): The API key used for authentication. If not provided, the class usesprocess.env.LLMWHISPERER_API_KEY
. - loggingLevel (
string
, optional): The logging level for the logger, such asdebug
,info
,warn
, orerror
. Defaults todebug
if not provided.
Properties:
- baseUrl (
string
): The base URL for the API. - apiKey (
string
): The API key used for authentication. - loggingLevel (
string
): The logging level for the client. - logger (
Object
): A logger instance created using thewinston
logging library.
Methods
getUsageInfo()
Description:
This method retrieves usage information from the API.
Returns:
- A
Promise<Object>
containing the usage information.
Throws:
LLMWhispererClientException
: If an error occurs during the API call.
whisper(options)
Description:
This method processes a file or URL using the LLMWhisperer API.
Parameters:
- filePath (
string
, optional): The path to the file to be processed. - url (
string
, optional): The URL of the file to be processed. - mode (
string
, optional): The processing mode, e.g.,high_quality
. Defaults tohigh_quality
. - outputMode (
string
, optional): The mode of output, e.g.,line-printer
. Defaults toline-printer
. - pageSeparator (
string
, optional): The separator for pages in the output. Defaults to<<<
. - pagesToExtract (
string
, optional): Specific pages to extract. Defaults to an empty string. - medianFilterSize (
number
, optional): The size of the median filter. Defaults to0
. - gaussianBlurRadius (
number
, optional): The radius of the Gaussian blur. Defaults to0
. - lineSplitterTolerance (
number
, optional): The tolerance for splitting lines. Defaults to0.4
. - horizontalStretchFactor (
number
, optional): The horizontal stretch factor. Defaults to1.0
. - markVerticalLines (
boolean
, optional): Whether to mark vertical lines. Defaults tofalse
. - markHorizontalLines (
boolean
, optional): Whether to mark horizontal lines. Defaults tofalse
. - lineSplitterStrategy (
string
, optional): The strategy for splitting lines, e.g.,left-priority
. Defaults toleft-priority
. - lang (
string
, optional): The language to use, e.g.,eng
. Defaults toeng
. - tag (
string
, optional): The tag to use. Defaults todefault
. - filename (
string
, optional): The filename to use. - webhookMetadata (
string
, optional): Metadata for the webhook. - useWebhook (
string
, optional): Whether to use a webhook. - waitForCompletion (
boolean
, optional): Whether to wait for the operation to complete. Defaults tofalse
. - waitTimeout (
number
, optional): The timeout for waiting, in seconds. Defaults to180
.
Returns:
- A
Promise<Object>
containing the response from the whisper API.
Throws:
LLMWhispererClientException
: If an error occurs during the request.
whisperStatus(whisperHash)
Description:
This method retrieves the status of a whisper operation.
Parameters:
- whisperHash (
string
): The hash of the whisper operation whose status is to be retrieved.
Returns:
- A
Promise<Object>
containing the status of the whisper operation.
Throws:
LLMWhispererClientException
: If an error occurs during the request.
whisperRetrieve(whisperHash)
Description:
This method retrieves the result of a whisper operation.
Parameters:
- whisperHash (
string
): The hash of the whisper operation whose result is to be retrieved.
Returns:
- A
Promise<Object>
containing the result of the whisper operation.
Throws:
LLMWhispererClientException
: If an error occurs during the request.
registerWebhook(webhookUrl, authToken, webhookName)
Description:
This method registers a webhook.
Parameters:
- webhookUrl (
string
): The URL of the webhook. - authToken (
string
): The authentication token for the webhook. - webhookName (
string
): The name of the webhook.
Returns:
- A
Promise<Object>
containing the response from the webhook registration.
Throws:
LLMWhispererClientException
: If an error occurs during the request.
getWebhookDetails(webhookName)
Description:
This method retrieves the details of a registered webhook.
Parameters:
- webhookName (
string
): The name of the webhook.
Returns:
- A
Promise<Object>
containing the details of the webhook.
Throws:
LLMWhispererClientException
: If an error occurs during the request.
getHighlightRect
Description:
Given the line metadata and the line number, this function returns the bounding box of the line
Parameters
lineMetadata
(Array): An array containing the line metadata returned by the LLMWhisperer API. It typically includes information such as page number, line position, line height, and original document height.targetWidth
(number): The width of the target image or page in the UI where the line is being highlighted.targetHeight
(number): The height of the target image or page in the UI.
Returns
Object
: An object containing the bounding box coordinates of the line in the following format:page
(number): The page number where the line is located.x1
(number): The x-coordinate of the top-left corner of the bounding box (fixed at 0).y1
(number): The y-coordinate of the top-left corner, scaled based on the target height.x2
(number): The x-coordinate of the bottom-right corner (equal totargetWidth
).y2
(number): The y-coordinate of the bottom-right corner, scaled based on the target height.
Exception Handling
LLMWhispererClientException
Description:
This is a custom exception class used by the LLMWhispererClientV2
class to handle errors during API interactions.
Constructor Parameters:
- message (
string
): The error message. - statusCode (
number
): The HTTP status code related to the error.
Methods:
- errorMessage(): Returns the error message.