Skip to content

Commit

Permalink
Fix dtype issue and summary parsing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
susilnem committed Oct 25, 2024
1 parent d682f6c commit 0c3e16f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions per/ops_learning_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def fetch_ops_learnings(self, filter_data):
"region_name",
"appeal_name",
"appeal_year",
"dtype_name",
)
)
ops_learning_df = ops_learning_df.rename(
Expand Down Expand Up @@ -436,7 +437,7 @@ def _identify_type_prioritization(df):
return None

def _contextualize_learnings(df):
"""Adds appeal year and event name as a contextualization of the leannings."""
"""Adds appeal year and event name as a contextualization of the learnings."""
for index, row in df.iterrows():
df.at[index, "learning"] = (
f"{row['excerpts_id']}. In {row['appeal_year']} in {row['appeal_name']}: {row['learning']}"
Expand Down Expand Up @@ -738,8 +739,11 @@ def _validate_format(summary, MAX_RETRIES=3):
"""

def _validate_text_is_dictionary(text):
formatted_text = ast.literal_eval(text)
return isinstance(formatted_text, dict)
try:
formatted_text = ast.literal_eval(text)
return isinstance(formatted_text, dict)
except Exception:
return False

def _modify_format(summary) -> str:
try:
Expand All @@ -752,8 +756,7 @@ def _modify_format(summary) -> str:
logger.info("Modification realized to response")
return formatted_summary

except Exception as e:
logger.error(f"Modification failed: {e}", exc_info=True)
except Exception:
return "{}"

formatted_summary = {}
Expand Down
2 changes: 1 addition & 1 deletion per/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def generate_ops_learning_summary(ops_learning_summary_id: int, filter_data: dic
OpsLearningSummaryTask.change_ops_learning_status(
instance=ops_learning_summary_instance, status=OpsLearningCacheResponse.Status.NO_EXTRACT_AVAILABLE
)
logger.error("No extracts found", exc_info=True)
logger.info("No extracts found")
return False


Expand Down

0 comments on commit 0c3e16f

Please sign in to comment.