@@ -155,6 +155,44 @@ def get_usage_info(self) -> dict:
155155 raise LLMWhispererClientException (err )
156156 return json .loads (response .text )
157157
158+ def get_highlight_data (self , whisper_hash : str , lines : str , extract_all_lines : bool = False ) -> dict :
159+ """Retrieves the highlight information of the LLMWhisperer API.
160+
161+ This method sends a GET request to the '/highlights' endpoint of the LLMWhisperer API.
162+ The response is a JSON object containing the usage information.
163+ Refer to https://docs.unstract.com/llm_whisperer/apis/llm_whisperer_usage_api
164+
165+ Args:
166+ whisper_hash (str): The hash of the whisper operation.
167+ lines (str): Define which lines metadata to retrieve.
168+ You can specify which lines metadata to retrieve with this parameter.
169+ Example 1-5,7,21- will retrieve lines metadata 1,2,3,4,5,7,21,22,23,24...
170+ till the last line meta data.
171+ Returns:
172+ dict: A dictionary containing the highlight information.
173+
174+ Raises:
175+ LLMWhispererClientException: If the API request fails, it raises an exception with
176+ the error message and status code returned by the API.
177+ """
178+ self .logger .debug ("highlight called" )
179+ url = f"{ self .base_url } /highlights"
180+ params = {
181+ "whisper_hash" : whisper_hash ,
182+ "lines" : lines ,
183+ "extract_all_lines" : extract_all_lines ,
184+ }
185+ self .logger .debug ("url: %s" , url )
186+ req = requests .Request ("GET" , url , headers = self .headers , params = params )
187+ prepared = req .prepare ()
188+ s = requests .Session ()
189+ response = s .send (prepared , timeout = self .api_timeout )
190+ if response .status_code != 200 :
191+ err = json .loads (response .text )
192+ err ["status_code" ] = response .status_code
193+ raise LLMWhispererClientException (err )
194+ return json .loads (response .text )
195+
158196 def whisper (
159197 self ,
160198 file_path : str = "" ,
@@ -171,6 +209,7 @@ def whisper(
171209 mark_vertical_lines : bool = False ,
172210 mark_horizontal_lines : bool = False ,
173211 line_spitter_strategy : str = "left-priority" ,
212+ add_line_nos : bool = False ,
174213 lang = "eng" ,
175214 tag = "default" ,
176215 filename = "" ,
@@ -201,6 +240,8 @@ def whisper(
201240 mark_vertical_lines (bool, optional): Whether to mark vertical lines. Defaults to False.
202241 mark_horizontal_lines (bool, optional): Whether to mark horizontal lines. Defaults to False.
203242 line_spitter_strategy (str, optional): The line splitter strategy. Defaults to "left-priority".
243+ add_line_nos (bool, optional): Adds line numbers to the extracted text and saves line metadata,
244+ which can be queried later using the highlights API.
204245 lang (str, optional): The language of the document. Defaults to "eng".
205246 tag (str, optional): The tag for the document. Defaults to "default".
206247 filename (str, optional): The name of the file to store in reports. Defaults to "".
@@ -235,6 +276,7 @@ def whisper(
235276 "mark_vertical_lines" : mark_vertical_lines ,
236277 "mark_horizontal_lines" : mark_horizontal_lines ,
237278 "line_spitter_strategy" : line_spitter_strategy ,
279+ "add_line_nos" : add_line_nos ,
238280 "lang" : lang ,
239281 "tag" : tag ,
240282 "filename" : filename ,
0 commit comments