Skip to content
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

Update bracket_termination.py #2094

Closed
wants to merge 1 commit into from

Conversation

amrshady
Copy link

Background

This pull request aims to enhance the robustness of the JSON parsing and fixing functions in the Auto-GPT project. The changes improve the code's readability and maintainability, while also addressing potential edge cases that could lead to issues in JSON processing.

Changes

  • Refactored the existing JSON fixing and parsing functions to make them more modular.
  • Improved exception handling and error messages to provide better debugging information.
  • Added type hints and comments to make the code more readable and maintainable.
  • Updated the function documentation to better explain their purpose and usage.

Documentation

The changes are documented through in-code comments and updated function docstrings. The new code follows the project's coding standards and conventions, making it easy to understand and maintain.

Test Plan

  • Test the updated JSON parsing and fixing functions with various JSON inputs, including valid JSON, JSON with missing or extra braces, and JSON with invalid escape sequences.
  • Test the updated functions with edge cases and inputs that could potentially lead to issues in the original implementation.
  • Ensure that the changes do not introduce any new bugs or regressions.

PR Quality Checklist

x My pull request is atomic and focuses on a single change.
x I have thoroughly tested my changes with multiple different prompts.
x I have considered potential risks and mitigations for my changes.
x I have documented my changes clearly and comprehensively.
x I have not snuck in any "extra" small tweaks changes

Copy link

@WilliamKernsAI WilliamKernsAI Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#import logging
from colorama import Fore

#logging.basicConfig(level=logging.DEBUG)
from autogpt.logs import logger
#logger = logging.getLogger(__name__)
from autogpt.config import Config

CFG = Config()

def attempt_to_fix_json_by_finding_outermost_brackets(json_string: str):
    logger.typewriter_log("Attempting to fix JSON by finding outermost brackets\n")
    json_pattern = regex.compile(r"\{(?:[^{}]|(?R))*\}")
    json_match = json_pattern.search(json_string)

    if json_match:
        json_string = json_match.group(0)
        logger.typewriter_log(
                title="Apparently json was fixed.", title_color=Fore.GREEN)
    else:
        logger.error("No valid JSON object found")
        json_string = "{}"

    return json_string

@nponeccop nponeccop added the invalid_json Groups issues and PRs related to invalid json error or similar label Apr 17, 2023
@github-actions github-actions bot added the conflicts Automatically applied to PRs with merge conflicts label Apr 17, 2023
@github-actions
Copy link
Contributor

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

@p-i-
Copy link
Contributor

p-i- commented May 5, 2023

This is a mass message from the AutoGPT core team.
Our apologies for the ongoing delay in processing PRs.
This is because we are re-architecting the AutoGPT core!

For more details (and for infor on joining our Discord), please refer to:
https://github.com/Significant-Gravitas/Auto-GPT/wiki/Architecting

@Pwuts
Copy link
Member

Pwuts commented Jun 14, 2023

Thanks for submitting! JSON syntax has been a very prominent issue, and has also received a lot of attention in PR submissions and issues. I am fairly sure this PR has been superseded by #4655, which also uses the JSON schema to improve the LLMs obedience to the desired output format. Still, we appreciate the submission and if you are still interested to contribute, be sure to get in contact via discord!

Closing as superseded by #4655

@Pwuts Pwuts closed this Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conflicts Automatically applied to PRs with merge conflicts invalid_json Groups issues and PRs related to invalid json error or similar
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants