@@ -222,15 +222,14 @@ def calculate_cost_and_tokens(result):
222
222
223
223
# Exract error message from the result JSON
224
224
def extract_error_message (result ):
225
- result_data = json .loads (result )
226
225
# Check for error in extraction_result
227
- extraction_result = result_data .get ("extraction_result" , [])
226
+ extraction_result = result .get ("extraction_result" , [])
228
227
if extraction_result and isinstance (extraction_result , list ):
229
228
for item in extraction_result :
230
229
if "error" in item and item ["error" ]:
231
230
return item ["error" ]
232
231
# Fallback to the parent error
233
- return result_data .get ("error" , "No error message found" )
232
+ return result .get ("error" , "No error message found" )
234
233
235
234
# Print final summary with count of each status and average time using a single SQL query
236
235
def print_summary ():
@@ -275,34 +274,49 @@ def print_report():
275
274
if report_data :
276
275
# Tabulate the data with column headers
277
276
headers = [
278
- textwrap .fill (header , width = 20 )
279
- for header in [
280
- "File Name" ,
281
- "Execution Status" ,
282
- "Time Elapsed (seconds)" ,
283
- "Total Embedding Cost" ,
284
- "Total Embedding Tokens" ,
285
- "Total LLM Cost" ,
286
- "Total LLM Tokens" ,
287
- "Error Message"
288
- ]
277
+ "File Name" ,
278
+ "Execution Status" ,
279
+ "Time Elapsed (seconds)" ,
280
+ "Total Embedding Cost" ,
281
+ "Total Embedding Tokens" ,
282
+ "Total LLM Cost" ,
283
+ "Total LLM Tokens" ,
284
+ "Error Message"
289
285
]
290
-
286
+
287
+ column_widths = {
288
+ "File Name" : 30 ,
289
+ "Execution Status" : 20 ,
290
+ "Time Elapsed (seconds)" : 20 ,
291
+ "Total Embedding Cost" : 20 ,
292
+ "Total Embedding Tokens" : 20 ,
293
+ "Total LLM Cost" : 20 ,
294
+ "Total LLM Tokens" : 20 ,
295
+ "Error Message" : 30 ,
296
+ }
291
297
292
298
formatted_data = []
293
- # Wrap text in each column to a specific width (e.g., 30 characters for file names and 20 for others) and return None if the value is NULL
299
+ # Format and wrap each row's data to match column widths
294
300
for row in report_data :
295
- formatted_row = [
296
- "None" if cell is None else
297
- textwrap .fill (str (cell ), width = 30 ) if isinstance (cell , str ) else
298
- cell if idx == 2 else f"{ cell :.8f} " if isinstance (cell , float ) else cell
299
- for idx , cell in enumerate (row )
300
- ]
301
- formatted_data .append (formatted_row )
302
-
301
+ formatted_row = []
302
+ for idx , cell in enumerate (row ):
303
+ header = headers [idx ]
304
+ width = column_widths [header ]
305
+ cell_value = "None" if cell is None else str (cell )
306
+ if header == "Error Message" and len (cell_value ) > 50 :
307
+ # Truncate long error messages
308
+ cell_value = textwrap .fill (cell_value [:100 ], width = width ) + "..."
309
+ else :
310
+ cell_value = textwrap .fill (cell_value , width = width )
311
+ formatted_row .append (cell_value )
312
+ formatted_data .append (formatted_row )
313
+
314
+ # Print the table
303
315
print (tabulate (formatted_data , headers = headers , tablefmt = "pretty" ))
304
316
else :
305
317
print ("No records found in the database." )
318
+
319
+ print ("\n Note: For more detailed error messages, use the CSV report argument." )
306
320
307
321
def export_report_to_csv (output_path ):
308
322
conn = sqlite3 .connect (DB_NAME )
@@ -621,4 +635,4 @@ def main():
621
635
622
636
623
637
if __name__ == "__main__" :
624
- main ()
638
+ main ()
0 commit comments