Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix!: Remove JSON parsing error and update detailed report formatting #12

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,14 @@ def calculate_cost_and_tokens(result):

# Exract error message from the result JSON
def extract_error_message(result):
result_data = json.loads(result)
# Check for error in extraction_result
extraction_result = result_data.get("extraction_result", [])
extraction_result = result.get("extraction_result", [])
if extraction_result and isinstance(extraction_result, list):
for item in extraction_result:
if "error" in item and item["error"]:
return item["error"]
# Fallback to the parent error
return result_data.get("error", "No error message found")
return result.get("error", "No error message found")

# Print final summary with count of each status and average time using a single SQL query
def print_summary():
Expand Down Expand Up @@ -263,7 +262,7 @@ def print_report():
# Fetch required fields, including total_cost and total_tokens
c.execute(
"""
SELECT file_name, execution_status, time_taken, total_embedding_cost, total_embedding_tokens, total_llm_cost, total_llm_tokens, error_message
SELECT file_name, execution_status, time_taken, total_embedding_cost, total_embedding_tokens, total_llm_cost, total_llm_tokens
ritwik-g marked this conversation as resolved.
Show resolved Hide resolved
FROM file_status
"""
)
Expand All @@ -284,7 +283,6 @@ def print_report():
"Total Embedding Tokens",
"Total LLM Cost",
"Total LLM Tokens",
"Error Message"
]
]

Expand All @@ -304,6 +302,9 @@ def print_report():
else:
print("No records found in the database.")

# Suggest CSV report for error details
print("\nNote: Use the `--export_csv` argument to generate a CSV report that includes error messages.")

def export_report_to_csv(output_path):
conn = sqlite3.connect(DB_NAME)
c = conn.cursor()
Expand Down
Loading