@@ -435,6 +435,10 @@ class LLMWhispererClientV2 {
435
435
* @param {string } [options.useWebhook=''] - Whether to use a webhook.
436
436
* @param {boolean } [options.waitForCompletion=false] - Whether to wait for completion.
437
437
* @param {number } [options.waitTimeout=180] - The timeout for waiting.
438
+ * @param {boolean } [options.addLineNos=false] - If true, adds line numbers to the extracted text
439
+ * and saves line metadata, which can be queried later
440
+ * using the highlights API.
441
+
438
442
* @returns {Promise<Object> } The response from the whisper API.
439
443
* @throws {LLMWhispererClientException } If there is an error in the request.
440
444
*/
@@ -459,6 +463,7 @@ class LLMWhispererClientV2 {
459
463
useWebhook = "" ,
460
464
waitForCompletion = false ,
461
465
waitTimeout = 180 ,
466
+ addLineNos = false ,
462
467
} = { } ) {
463
468
this . logger . debug ( "whisper called" ) ;
464
469
const apiUrl = `${ this . baseUrl } /whisper` ;
@@ -482,6 +487,7 @@ class LLMWhispererClientV2 {
482
487
use_webhook : useWebhook ,
483
488
wait_for_completion : waitForCompletion ,
484
489
wait_timeout : waitTimeout ,
490
+ add_line_nos : addLineNos ,
485
491
} ;
486
492
487
493
this . logger . debug ( `api_url: ${ apiUrl } ` ) ;
@@ -741,6 +747,55 @@ class LLMWhispererClientV2 {
741
747
} ;
742
748
}
743
749
}
750
+
751
+ /**
752
+ * Retrieves the highlight information of the LLMWhisperer API.
753
+ *
754
+ * This method sends a GET request to the '/highlights' endpoint of the LLMWhisperer API.
755
+ * The response is a JSON object containing the usage information.
756
+ * Refer to https://docs.unstract.com/llm_whisperer/apis/llm_whisperer_usage_api
757
+ *
758
+ * @param {string } whisperHash - The hash of the whisper operation.
759
+ * @param {string } lines - Define which lines metadata to retrieve.
760
+ * Example "1-5,7,21-" retrieves lines 1,2,3,4,5,7,21,22,23,...
761
+ * @param {boolean } [extractAllLines=false] - If true, extract all lines.
762
+ * @returns {Promise<Object> } A promise that resolves with the highlight information.
763
+ * @throws {LLMWhispererClientException } If the API request fails.
764
+ */
765
+ async getHighlightData ( whisperHash , lines , extractAllLines = false ) {
766
+ this . logger . debug ( "highlight called" ) ;
767
+ const url = `${ this . baseUrl } /highlights` ;
768
+
769
+ // Build query parameters
770
+ const params = {
771
+ whisper_hash : whisperHash ,
772
+ lines : lines ,
773
+ extract_all_lines : extractAllLines ,
774
+ } ;
775
+
776
+ try {
777
+ const response = await axios ( url , {
778
+ method : "GET" ,
779
+ headers : this . headers ,
780
+ params : params ,
781
+ } ) ;
782
+
783
+ if ( response . status != 200 ) {
784
+ // Parse error response and throw a custom exception
785
+ const errorData = await response . data ;
786
+ errorData . status_code = response . status ;
787
+ throw new LLMWhispererClientException ( errorData ) ;
788
+ }
789
+
790
+ return response . data ;
791
+ } catch ( error ) {
792
+ const err = error . response
793
+ ? error . response . data
794
+ : { message : error . message } ;
795
+ err . statusCode = error . response ? error . response . status : - 1 ;
796
+ throw new LLMWhispererClientException ( err . message , err . statusCode ) ;
797
+ }
798
+ }
744
799
}
745
800
746
801
module . exports = {
0 commit comments