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

Fixed Json Error #285

Closed
wants to merge 1 commit into from
Closed

Conversation

AGI-CEO
Copy link

@AGI-CEO AGI-CEO commented Apr 6, 2023

Fixed the json_parser.py error by making chatgpt fix itself

def fix_and_parse_json(json_str: str, try_to_fix_with_gpt: bool = True):
json_schema = """
{
"command": {
"name": "command name",
"args":{
"arg name": "value"
}
},
"thoughts":
{
"text": "thought",
"reasoning": "reasoning",
"plan": "- short bulleted\n- list that conveys\n- long-term plan",
"criticism": "constructive self-criticism",
"speak": "thoughts summary to say to user"
}
}
"""

def clean_input(json_str):
    brace_index = json_str.index("{")
    json_str = json_str[brace_index:]
    last_brace_index = json_str.rindex("}")
    json_str = json_str[:last_brace_index+1]
    return json_str

def attempt_parse(json_str):
    try:
        return json.loads(json_str)
    except Exception as e:
        return None

cleaned_json_str = clean_input(json_str)
parsed_json = attempt_parse(cleaned_json_str)

if parsed_json is not None:
    return parsed_json
elif try_to_fix_with_gpt:
    print("Warning: Failed to parse AI output, attempting to fix.")
    ai_fixed_json = fix_json(cleaned_json_str, json_schema, False)

    if ai_fixed_json != "failed":
        return json.loads(ai_fixed_json)
    else:
        print("Failed to fix ai output, telling the AI.")
        return json_str

raise ValueError("Failed to parse JSON: '{}'".format(json_str))

except Exception as e:
if try_to_fix_with_gpt:
print(f"Warning: Failed to parse AI output, attempting to fix.\n If you see this warning frequently, it's likely that your prompt is confusing the AI. Try changing it up slightly.")
Copy link

Choose a reason for hiding this comment

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

Why get rid of this message about confusing the AI?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, please add this back in.

return json_str
else:
raise e
return None
Copy link

Choose a reason for hiding this comment

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

Why not keep the try/except error handling paradigm?

json_str = json_str[:last_brace_index+1]
return json_str

def attempt_parse(json_str):
Copy link

Choose a reason for hiding this comment

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

Why not un-nest these functions while you're at it?

@Torantulino
Copy link
Member

What are all these new .idea files?

Copy link
Member

Choose a reason for hiding this comment

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

I assume you added these by mistake?
Please remove them.

@Torantulino Torantulino added the question Further information is requested label Apr 6, 2023
@ksylvan
Copy link

ksylvan commented Apr 8, 2023

What are all these new .idea files?

@Torantulino Those are IntelliJ IDE files that people keep pushing by mistake. We can add those to .gitignore so we don't get them in PRs.

@nponeccop
Copy link
Contributor

@ksylvan Add them in a separate PR. Also resolve the conflicts.

This was referenced Apr 10, 2023
@ksylvan
Copy link

ksylvan commented Apr 12, 2023

@nponeccop Not my PR, I was just commenting on it, since I'd seen a few different PRs with .idea/ files in them. @jetblaise is the original author here.

@nponeccop
Copy link
Contributor

@jetblaise Could you resolve the conflicts?

@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.

1 similar comment
@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

Closing this PR as it has conflicts and long-standing unresolved requests for changes

@Pwuts Pwuts closed this Jun 14, 2023
waynehamadi added a commit that referenced this pull request Sep 5, 2023
Signed-off-by: Merwane Hamadi <merwanehamadi@gmail.com>
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 question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants