Skip to content

Commit

Permalink
[IMP] Remove possible markdown code block from openai response
Browse files Browse the repository at this point in the history
  • Loading branch information
maschlr committed Aug 22, 2024
1 parent 34e736b commit 9d91baa
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion summaree_bot/integrations/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ def get_openai_chatcompletion(messages: list[dict], n_retry: int = 1, max_retrie
)
try:
[choice] = summary_result.choices
data = json.loads(choice.message.content)
if choice.message.content.startswith("```"):
json_str = "\n".join(choice.message.content.splitlines()[1:-1])
else:
json_str = choice.message.content
data = json.loads(json_str)
except IndexError:
_logger.error(f"OpenAI returned more than one or no choices: {summary_result}")
raise
Expand Down

0 comments on commit 9d91baa

Please sign in to comment.