Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ let response = veryfi_client.process_document_from_url(url, null, categories, fa
});
```

Run thinking on the line items with `thinking` (`'light'` or `'deep'`; omit it to turn it off). Every `process_document*` method accepts it in the extra parameters, and `'deep'` takes longer than `'light'`. It only takes effect if thinking mode is enabled for your account.

```js
let response = veryfi_client.process_document(file_path, categories, false, {thinking: 'light'}).then(response => {
console.log(response)
});
```

### Line items, tags, and other products

```js
Expand Down
1 change: 1 addition & 0 deletions lib/documents/processDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const fs = require('fs');
* @param {Array} categories List of categories Veryfi can use to categorize the document
* @param {Boolean} auto_delete Delete this document from Veryfi after data has been extracted
* @param {Object} kwargs Additional request parameters
* @param {('light'|'deep')} [kwargs.thinking] Extra LLM pass on the line items: "light" or "deep" (slower). Omit to turn it off. Needs thinking mode enabled for your account.
* @returns {JSON} Data extracted from the document
*/
Client.prototype.process_document = async function (
Expand Down
1 change: 1 addition & 0 deletions lib/documents/processDocumentBase64.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const Client = require('../client/constructor');
* @param {Array} categories List of categories Veryfi can use to categorize the document
* @param {Boolean} auto_delete Delete this document from Veryfi after data has been extracted
* @param {Object} kwargs Additional request parameters
* @param {('light'|'deep')} [kwargs.thinking] Extra LLM pass on the line items: "light" or "deep" (slower). Omit to turn it off. Needs thinking mode enabled for your account.
* @returns {JSON} Data extracted from the document
*/
Client.prototype.process_document_from_base64 = async function (
Expand Down
1 change: 1 addition & 0 deletions lib/documents/processDocumentStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Client = require('../client/constructor');
* @param {String} file_name The file name including the extension
* @param {Boolean} auto_delete Delete this document from Veryfi after data has been extracted
* @param {Object} kwargs Additional request parameters (categories, tags, async, parse_address, crop_document, compute, country, document_type, device_data, package_path, bucket, bounding_boxes, confidence_details)
* @param {('light'|'deep')} [kwargs.thinking] Extra LLM pass on the line items: "light" or "deep" (slower). Omit to turn it off. Needs thinking mode enabled for your account.
* @returns {JSON} Data extracted from the document
*/
Client.prototype.process_document_from_stream = async function (
Expand Down
3 changes: 2 additions & 1 deletion lib/documents/processDocumentUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const Client = require('../client/constructor');
* @param {boolean} boost_mode Flag that tells Veryfi whether boost mode should be enabled. When set to 1, Veryfi will skip data enrichment steps, but will process the document faster. Default value for this flag is 0
* @param {string|null} external_id Optional custom document identifier. Use this if you would like to assign your own ID to documents
* @param {int} max_pages_to_process When sending a long document to Veryfi for processing, this parameter controls how many pages of the document will be read and processed, starting from page 1.
* @param {Object} kwargs Additional request parameters (async, tags, parse_address, crop_document, compute, country, document_type, device_data, package_path, bucket, bounding_boxes, confidence_details, thinking, thinking_llm_version, allowed_async_enrichments, emailed_receipt_id, receipt_id)
* @param {Object} kwargs Additional request parameters (async, tags, parse_address, crop_document, compute, country, document_type, device_data, package_path, bucket, bounding_boxes, confidence_details, thinking_llm_version, allowed_async_enrichments, emailed_receipt_id, receipt_id)
* @param {('light'|'deep')} [kwargs.thinking] Extra LLM pass on the line items: "light" or "deep" (slower). Omit to turn it off. Needs thinking mode enabled for your account.
* @return {JSON} Data extracted from the document.
*/
Client.prototype.process_document_from_url = async function (
Expand Down
8 changes: 7 additions & 1 deletion lib/types/VeryfiExtraArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
* Nested objects, arrays, and nulls are allowed because several Veryfi
* body fields (device_data, vendor, line_items, document_types, tags) are not scalars.
*/
export declare type VeryfiExtraArgs = Record<string | number | symbol, any>;
export declare type VeryfiExtraArgs = Record<string | number | symbol, any> & {
/**
* Extra LLM pass on the line items: "light" or "deep" (slower).
* Omit to turn it off. Needs thinking mode enabled for your account.
*/
thinking?: "light" | "deep";
};

export type JsonObject = Record<string, any>;
48 changes: 48 additions & 0 deletions test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,54 @@ describe('Processing documents', () => {
});
});

describe('Thinking parameter', () => {
const newClient = () => {
const client = new Client('client_id', undefined, 'username', 'api_key');
client._request = jest.fn().mockResolvedValue({data: {}});
return client;
};
// request_arguments is the third argument of _request
const sentArguments = (client) => client._request.mock.calls[0][2];

test.each(['light', 'deep'])('process_document sends thinking=%s', async (mode) => {
const client = newClient();
await client.process_document('resources/receipt.png', null, false, {thinking: mode});
expect(sentArguments(client).thinking).toBe(mode);
});

test('process_document does not send thinking when omitted', async () => {
const client = newClient();
await client.process_document('resources/receipt.png');
expect(sentArguments(client)).not.toHaveProperty('thinking');
});

test.each(['light', 'deep'])('process_document_from_base64 sends thinking=%s', async (mode) => {
const client = newClient();
await client.process_document_from_base64('ZmFrZQ==', 'receipt.png', null, false, {thinking: mode});
expect(sentArguments(client).thinking).toBe(mode);
});

test.each(['light', 'deep'])('process_document_from_stream sends thinking=%s', async (mode) => {
const client = newClient();
const stream = fs.createReadStream('resources/receipt.png');
await client.process_document_from_stream(stream, 'receipt.png', false, {thinking: mode});
stream.destroy();
expect(sentArguments(client).thinking).toBe(mode);
});

test.each(['light', 'deep'])('process_document_from_url sends thinking=%s', async (mode) => {
const client = newClient();
await client.process_document_from_url('https://cdn.example.com/receipt.jpg', null, null, false, false, null, 1, {thinking: mode});
expect(sentArguments(client).thinking).toBe(mode);
});

test('process_document_from_url does not send thinking when omitted', async () => {
const client = newClient();
await client.process_document_from_url('https://cdn.example.com/receipt.jpg');
expect(sentArguments(client)).not.toHaveProperty('thinking');
});
});

describe('Managing documents', () => {
test('Get documents', async () => {
try {
Expand Down
Loading