Skip to content

Commit

Permalink
Remove ```json wrapped content from openai completions response
Browse files Browse the repository at this point in the history
FIXME: Replace openai legacy api
  • Loading branch information
thenav56 committed Feb 7, 2025
1 parent ea31843 commit f53cc58
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions per/ops_learning_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,11 +837,17 @@ def _validate_text_is_dictionary(text) -> bool:

def _modify_format(summary) -> str:
try:
formatted_summary = summary
# If the content is wrapped in ```json and clean it up
if formatted_summary.startswith("```json") and formatted_summary.endswith("```"):
# Strip the backticks and any surrounding whitespace
formatted_summary = formatted_summary.strip("```json").strip().strip("```")

# Find the index of the last closing brace before the "Note"
end_index = summary.rfind("}")
end_index = formatted_summary.rfind("}")

# Truncate the string to include only the dictionary part
formatted_summary = summary[: end_index + 1]
formatted_summary = formatted_summary[: end_index + 1]

logger.info("Modification realized to response")
return formatted_summary
Expand Down

0 comments on commit f53cc58

Please sign in to comment.