LLMWhisperer JavaScript Client
The `llmwhisperer-client` is a JavaScript client library designed to facilitate interaction with the LLMWhisper API. Its primary function is to preprocess complex documents, such as PDFs and images, to extract raw text in a format optimized for consumption by Large Language Models. The library, currently at stable version 2.5.0, appears to follow an active release cadence with frequent minor updates. Key differentiators include a "Layout Preserving Mode" for maintaining document structure, automatic switching between native text and OCR modes, and intelligent handling of interactive elements like checkboxes in PDF forms. This enables robust and accurate structured data extraction from various document types, including invoices, purchase orders, and bank statements, by presenting data to LLMs in their most understandable form.
Common errors
-
TypeError: LLMWhispererClient is not a constructor
cause Attempting to instantiate the removed V1 client after upgrading to version `2.5.0` or higher.fixUpdate your code to use `LLMWhispererClientV2`. Change `new LLMWhispererClient(...)` to `new LLMWhispererClientV2(...)`. -
Error: API key is missing or invalid.
cause The `apiKey` was not provided in the client options object, and the `LLMWHISPERER_API_KEY` environment variable is not set.fixProvide the API key: `new LLMWhispererClientV2({ apiKey: 'YOUR_API_KEY' })` or set `LLMWHISPERER_API_KEY=YOUR_API_KEY` in your environment. -
ReferenceError: require is not defined in ES module scope
cause Using CommonJS `require()` syntax (`const { ... } = require(...)`) in an ES Module project (`"type": "module"` in `package.json`).fixChange the import statement to use ES module syntax: `import { LLMWhispererClientV2 } from 'llmwhisperer-client';`.
Warnings
- breaking As of version `2.5.0`, the previously deprecated V1 client (e.g., `LLMWhispererClient` without the `V2` suffix) has been completely removed. Applications still relying on V1 client imports or methods will encounter runtime errors.
- gotcha The LLMWhisperer client requires an API key for authentication. If the `LLMWHISPERER_API_KEY` environment variable is not set, the `apiKey` property must be explicitly provided in the options object during `LLMWhispererClientV2` instantiation.
- breaking Version `2.0.0` introduced `LLMWhispererClientV2`, signaling a major API revision. While specific breaking changes from a V1 client aren't detailed in the immediate changelog, the introduction of a new client class implies an incompatible API surface compared to any pre-2.0.0 client.
- gotcha Errors returned from the API or encountered internally by the client are typically wrapped in an `LLMWhispererClientException`. Neglecting to catch this specific exception type can lead to unhandled errors.
Install
-
npm install llmwhisperer-client -
yarn add llmwhisperer-client -
pnpm add llmwhisperer-client
Imports
- LLMWhispererClientV2
const { LLMWhispererClientV2 } = require('llmwhisperer-client');import { LLMWhispererClientV2 } from 'llmwhisperer-client'; - LLMWhispererClientException
import { LLMWhispererClientException } from 'llmwhisperer-client'; - LLMWhispererClientOptions
import type { LLMWhispererClientOptions } from 'llmwhisperer-client';
Quickstart
import { LLMWhispererClientV2 } from 'llmwhisperer-client';
// Configure the client. API key can be set via LLMWHISPERER_API_KEY env variable.
const options = {
apiKey: process.env.LLMWHISPERER_API_KEY ?? 'YOUR_SECRET_API_KEY',
baseUrl: process.env.LLMWHISPERER_BASE_URL ?? 'https://api.llmwhisperer.com/v2',
apiTimeout: 5000, // Timeout in milliseconds
loggingLevel: 'info' // 'error', 'warn', 'info', 'debug'
};
// Create a new client instance
const client = new LLMWhispererClientV2(options);
async function runWhisperExample() {
try {
// Replace with actual whisper options like document content, type, etc.
// This is a placeholder as the README does not provide a full `whisper` example.
// Example: const whisperResult = await client.whisper({ content: '...', type: 'pdf' });
console.log('Client initialized and ready to make API calls.');
console.log('You can now use methods like client.whisper(), client.whisperStatus(), etc.');
} catch (error) {
console.error('An error occurred:', error.message);
}
}
runWhisperExample();