@@ -60,38 +60,41 @@ def test_connection_request(
60
60
"Unable to connect to LLMWhisperer service, please check the URL" ,
61
61
actual_err = e ,
62
62
status_code = 503 ,
63
- )
63
+ ) from e
64
64
except Timeout as e :
65
65
msg = "Request to LLMWhisperer has timed out"
66
66
logger .error (f"{ msg } : { e } " )
67
- raise ExtractorError (msg , actual_err = e , status_code = 504 )
67
+ raise ExtractorError (msg , actual_err = e , status_code = 504 ) from e
68
68
except HTTPError as e :
69
69
logger .error (f"Adapter error: { e } " )
70
70
default_err = "Error while calling the LLMWhisperer service"
71
71
msg = AdapterUtils .get_msg_from_request_exc (
72
72
err = e , message_key = "message" , default_err = default_err
73
73
)
74
- raise ExtractorError (msg , status_code = e .response .status_code , actual_err = e )
74
+ raise ExtractorError (
75
+ msg , status_code = e .response .status_code , actual_err = e
76
+ ) from e
75
77
76
78
@staticmethod
77
79
def make_request (
78
80
config : dict [str , Any ],
79
81
headers : dict [str , Any ] | None = None ,
80
82
params : dict [str , Any ] | None = None ,
81
- data : Any | None = None ,
83
+ data : BytesIO | None = None ,
82
84
type : str = "whisper" ,
83
85
) -> Response :
84
86
"""Makes a request to LLMWhisperer service.
85
87
86
88
Args:
87
- request_method (HTTPMethod): HTTPMethod to call. Can be GET or POST
88
- request_endpoint (str): LLMWhisperer endpoint to hit
89
+ config (dict[str, Any]): LLMWhisperer config to use
89
90
headers (Optional[dict[str, Any]], optional): Headers to pass.
90
91
Defaults to None.
91
92
params (Optional[dict[str, Any]], optional): Query params to pass.
92
93
Defaults to None.
93
- data (Optional[Any ], optional): Data to pass in case of POST.
94
+ data (Optional[BytesIO ], optional): Data to pass in case of POST.
94
95
Defaults to None.
96
+ type (str, optional): Type of request / endpoint in LLMWhisperer.
97
+ Defaults to "whisper".
95
98
96
99
Returns:
97
100
Response: Response from the request
@@ -110,11 +113,19 @@ def make_request(
110
113
if type == "whisper" :
111
114
response = client .whisper (** params , stream = data )
112
115
if response ["status_code" ] == 200 :
116
+ logger .debug (
117
+ "Successfully extracted for whisper hash: "
118
+ f"{ response .get (X2TextConstants .WHISPER_HASH_V2 , '' )} "
119
+ )
113
120
response ["extraction" ][X2TextConstants .WHISPER_HASH_V2 ] = (
114
121
response .get (X2TextConstants .WHISPER_HASH_V2 , "" )
115
122
)
116
123
return response ["extraction" ]
117
124
else :
125
+ response ["message" ] += (
126
+ ". Whisper hash: "
127
+ f"{ response .get (X2TextConstants .WHISPER_HASH_V2 , '' )} "
128
+ )
118
129
raise ExtractorError (
119
130
response ["message" ],
120
131
response ["status_code" ],
@@ -130,18 +141,18 @@ def make_request(
130
141
"Unable to connect to LLMWhisperer service, please check the URL" ,
131
142
actual_err = e ,
132
143
status_code = 503 ,
133
- )
144
+ ) from e
134
145
except Timeout as e :
135
146
msg = "Request to LLMWhisperer has timed out"
136
147
logger .error (f"{ msg } : { e } " )
137
- raise ExtractorError (msg , actual_err = e , status_code = 504 )
148
+ raise ExtractorError (msg , actual_err = e , status_code = 504 ) from e
138
149
except LLMWhispererClientException as e :
139
150
logger .error (f"LLM Whisperer error: { e } " )
140
151
raise ExtractorError (
141
152
message = f"LLM Whisperer error: { e } " ,
142
153
actual_err = e ,
143
154
status_code = 500 ,
144
- )
155
+ ) from e
145
156
146
157
return response
147
158
@@ -251,7 +262,7 @@ def send_whisper_request(
251
262
response ["line_metadata" ] = highlight_data
252
263
except OSError as e :
253
264
logger .error (f"OS error while reading { input_file_path } : { e } " )
254
- raise ExtractorError (str (e ))
265
+ raise ExtractorError (str (e )) from e
255
266
return response
256
267
257
268
@staticmethod
@@ -261,10 +272,12 @@ def make_highlight_data_request(
261
272
"""Makes a call to get highlight data from LLMWhisperer.
262
273
263
274
Args:
275
+ config (dict[str, Any]): LLMWhisperer config to use
264
276
whisper_hash (str): Identifier of the extraction
277
+ enable_highlight (bool): Whether to enable highlight
265
278
266
279
Returns:
267
- str: Extracted contents from the file
280
+ dict[Any, Any]: Highlight data
268
281
"""
269
282
logger .info (f"Extracting async for whisper hash: { whisper_hash } " )
270
283
@@ -307,14 +320,17 @@ def write_output_to_file(
307
320
output_file_path : Path ,
308
321
fs : FileStorage = FileStorage (provider = FileStorageProvider .LOCAL ),
309
322
) -> None :
310
- """Writes the extracted text and metadata to the specified output file
323
+ """Write LLMW outputs to file.
324
+
325
+ Writes the extracted text and metadata to the specified output file
311
326
and metadata file.
312
327
313
328
Args:
314
329
output_json (dict): The dictionary containing the extracted data,
315
330
with "text" as the key for the main content.
316
331
output_file_path (Path): The file path where the extracted text
317
332
should be written.
333
+ fs (FileStorage): File storage instance to use for writing
318
334
319
335
Raises:
320
336
ExtractorError: If there is an error while writing the output file.
@@ -330,7 +346,7 @@ def write_output_to_file(
330
346
)
331
347
except Exception as e :
332
348
logger .error (f"Error while writing { output_file_path } : { e } " )
333
- raise ExtractorError (str (e ))
349
+ raise ExtractorError (str (e )) from e
334
350
try :
335
351
# Define the directory of the output file and metadata paths
336
352
output_dir = output_file_path .parent
0 commit comments