Skip to content

Remove ```json wrapped content from openai completions response #2401

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

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
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
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
Loading