AutoGPT icon indicating copy to clipboard operation
AutoGPT copied to clipboard

feat(autogpt): Implement tolerant `json_loads` function

Open kcze opened this issue 11 months ago ā€¢ 2 comments

OPEN-183

Background

OpenAI API tends to return broken json responses (such as trailing commas, extra newlines) which fail to be parsed by built-in json.loads. This change introduces relaxed parsing function json_loads using demjson3 that handles minor syntax issues in json and is used where json.loads was used previously to parse responses from llm. It can deal with:

  • Missing, extra and trailing commas
  • Extraneous newlines and whitespace outside of string literals
  • Inconsistent spacing after colons and commas
  • Missing closing brackets or braces
  • Numbers: binary, hex, octal, trailing and prefixed decimal points
  • Different encodings
  • Comments

Changes šŸ—ļø

  • Add dependency for demjson3 ^3.0.0 (LGPLv3 license)
  • json_loads function
  • Swap json.loads with json_loads across multiple files
  • Tests

kcze avatar Mar 14 '24 15:03 kcze

Deploy Preview for auto-gpt-docs ready!

Name Link
Latest commit 03df00be97e01d8fca7f9d07876bf93981382587
Latest deploy log https://app.netlify.com/sites/auto-gpt-docs/deploys/65fb52da4f4bfa0007abe779
Deploy Preview https://deploy-preview-7016--auto-gpt-docs.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Mar 14 '24 15:03 netlify[bot]

Do you have benchmark stats for this? Iā€™d like to see if it improves our score much

ntindle avatar Mar 14 '24 16:03 ntindle

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

github-actions[bot] avatar Mar 20 '24 16:03 github-actions[bot]

Conflicts have been resolved! šŸŽ‰ A maintainer will review the pull request shortly.

github-actions[bot] avatar Mar 20 '24 21:03 github-actions[bot]