Skip to content

Commit

Permalink
Updated the version to 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
johnyrahul committed Feb 4, 2025
1 parent 6149a91 commit 48c8393
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 88 deletions.
44 changes: 22 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
*
*/

require('dotenv').config()
const axios = require("axios");
const winston = require("winston");
const fs = require("fs");
const { register } = require("module");

const BASE_URL = "https://llmwhisperer-api.unstract.com/v1";
const BASE_URL_V2 = "https://llmwhisperer-api.us-central.unstract.com/api/v2";

Expand Down Expand Up @@ -55,6 +54,7 @@ class LLMWhispererClient {
apiTimeout = 120,
loggingLevel = "",
} = {}) {

const level =
loggingLevel || process.env.LLMWHISPERER_LOGGING_LEVEL || "debug";

Expand Down Expand Up @@ -374,8 +374,12 @@ class LLMWhispererClientV2 {

this.headers = {
"unstract-key": this.apiKey,
"Subscription-Id": "test", //TODO: Remove this line. For testing only
"Start-Date": "9-07-2024", //TODO: Remove this line. For testing only
"Subscription-Id": "jsclient-client",
"Subscription-Name": "jsclient-client",
"User-Id": "jsclient-client-user",
"Product-Id": "jsclient-client-product",
"Product-Name": "jsclient-client-product",
"Start-Date": "2024-07-09",
};
}

Expand Down Expand Up @@ -532,34 +536,27 @@ class LLMWhispererClientV2 {
message["extraction"] = {};
message["status_code"] = -1;
message["message"] = "Whisper client operation timed out";
break;
return message
}
const whisperStatus = await this.whisperStatus(whisperHash);

if (whisperStatus.statusCode !== 200) {
message["extraction"] = {};
message["status_code"] = whisperStatus.statusCode;
message["message"] = "Whisper client operation failed";
break;
return message
}
if (whisperStatus.status === "processing") {
if (whisperStatus.status === "accepted") {
this.logger.debug("Status: accepted");
} else if (whisperStatus.status === "processing") {
this.logger.debug("Status: processing");
} else if (whisperStatus.status === "delivered") {
this.logger.debug("Status: delivered");
throw new LLMWhispererClientException(
"Whisper operation already delivered",
-1,
);
} else if (whisperStatus.status === "unknown") {
this.logger.debug("Status: unknown");
throw new LLMWhispererClientException(
"Whisper operation status unknown",
-1,
);
} else if (whisperStatus.status === "failed") {
this.logger.debug("Status: failed");
} else if (whisperStatus.status === "error") {
this.logger.debug("Status: error");
this.logger.error('Whisper-hash: ${whisperHash} | STATUS: failed with ${whisperStatus.message}')
message["extraction"] = {};
message["status_code"] = -1;
message["message"] = "Whisper client operation failed";
message["status"] = "error";
message["message"] = whisperStatus.message;
break;
} else if (whisperStatus.status === "processed") {
this.logger.debug("Status: processed");
Expand Down Expand Up @@ -618,6 +615,9 @@ class LLMWhispererClientV2 {
message.statusCode = response.status;
return message;
} catch (error) {



const err = error.response
? error.response.data
: { message: error.message };
Expand Down
22 changes: 16 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
"license": "MIT",
"dependencies": {
"axios": "~1.7.2",
"llmwhisperer-client": "^2.0.1",
"winston": "~3.13.0"
},
"devDependencies": {
"@eslint/js": "^9.4.0",
"dotenv": "^16.4.5",
"dotenv": "^16.4.7",
"eslint": "^9.4.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-turbo": "^1.13.3",
Expand Down
1 change: 1 addition & 0 deletions test/data/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"test": "HelloWorld"}
6 changes: 3 additions & 3 deletions test/sample.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export LLMWHISPERER_BASE_URL=https://llmwhisperer-api.unstract.com/v1
export LLMWHISPERER_LOG_LEVEL=DEBUG
export LLMWHISPERER_API_KEY=
LLMWHISPERER_BASE_URL_V2=https://llmwhisperer-api.us-central.unstract.com/api/v2
LLMWHISPERER_LOG_LEVEL=DEBUG
LLMWHISPERER_API_KEY=
71 changes: 15 additions & 56 deletions test/test_v2.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,29 @@
const { LLMWhispererClientV2 } = require("../index");

var LLMWhispererClient = require("../index").LLMWhispererClient;
const { LLMWhispererClientV2 } = require("../index");

//const client = new LLMWhispererClient({apiKey:'c9b97420112f4c2aadae6fbda060680b'});
const client = new LLMWhispererClientV2();

(async () => {
// usage_info = await client.getUsageInfo();
// console.log(usage_info);
whisper = await client.whisper({filePath: 'data/restaurant_invoice_photo.pdf'});
//whisper = await client.whisper({url: 'https://storage.googleapis.com/pandora-static/samples/bill.jpg.pdf'});
// whisper = await client.whisper({
// filePath: 'sample_files/credit_card.pdf',
// processingMode: 'text',
// forceTextProcessing: true,
// pagesToExtract: '1-2',
// });
console.log(whisper);
usage_info = await client.getUsageInfo();
console.log(usage_info);

whisper_result = await client.whisper({
filePath: 'data/restaurant_invoice_photo.pdf', waitForCompletion: true,
waitTimeout: 120,
});
console.log(whisper_result);


//b4c25f17|5f1d285a7cf18d203de7af1a1abb0a3a
//whisper_status = await client.whisperStatus('b4c25f17|5f1d285a7cf18d203de7af1a1abb0a3a');
//console.log(whisper_status);
// whisper_result = await client.whisperRetrieve('b4c25f17|5f1d285a7cf18d203de7af1a1abb0a3a');
// console.log(whisper_result);

// whisper = await client.whisper({
// filePath: 'sample_files/restaurant_invoice_photo.pdf',
// waitForCompletion: true,
// waitTimeout: 120,
// });
// console.log(whisper);
whisper_result = await client.whisper({
filePath: 'data/test.json', waitForCompletion: true,
waitTimeout: 120,
});
console.log(whisper_result);

//result = await client.registerWebhook('https://webhook.site/2da127b3-003f-446d-a150-7a461a099f3c','','wb4');
//console.log(result);

//result = await client.getWebhookDetails('wb4');
//console.log(result);

// whisper = await client.whisper({
// filePath: "data/restaurant_invoice_photo.pdf",
// useWebhook: "wb4",
// webhookMetadata: "Sample Metadata",
// });

// whisper = await client.whisper({
// filePath: 'sample_files/credit_card.pdf',
// timeout: 1,
// storeMetadataForHighlighting: true,
// });
// //Keep checking the status until it is completed
// statusX = whisper.status;
// while (statusX === 'processing') {
// console.log('Processing... '+whisper['whisper-hash']);
// await new Promise(r => setTimeout(r, 3000));
// whisperStatus = await client.whisperStatus(whisper['whisper-hash']);
// statusX = whisperStatus.status;
// }
// if (statusX === 'processed') {
// //Retrieve the result
// whisper = await client.whisperRetrieve(whisper['whisper-hash']);
// console.log(whisper);
// } else {
// console.log('Error');
// }

// //41ebb056|ba4473ee92b30823c4ed3da759ef670f
// highlights = await client.highlightData('41ebb056|ba4473ee92b30823c4ed3da759ef670f', 'Pay by Computer');
// console.log(highlights);
})();

0 comments on commit 48c8393

Please sign in to comment.