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

Fix validate_json file error when cwd != project root #2665

Merged
merged 1 commit into from
Apr 21, 2023

Conversation

mickjagger19
Copy link
Contributor

Background

If running from any directory other than Auto-GPT, the program will crash, giving the following error message:

 File "AppData\Local\Programs\Python\Python311\Lib\site-packages\click\decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Auto-GPT\autogpt\cli.py", line 151, in main
    agent.start_interaction_loop()
  File "Auto-GPT\autogpt\agent\agent.py", line 86, in start_interaction_loop
    validate_json(assistant_reply_json, "llm_response_format_1")
  File "Auto-GPT\autogpt\json_utils\utilities.py", line 38, in validate_json
    with open(f"autogpt/json_utils/{schema_name}.json", "r") as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'autogpt/json_utils/llm_response_format_1.json'

This is caused by wrong location of llm_response_format_1.json, which can be easily fixed by building the path from concatenating script path and the json file name.

Changes

Change the building process of the path of llm_response_format_1.json into:

    script_dir = os.path.dirname(__file__)

    with open(os.path.join(script_dir, f"{schema_name}.json"), "r") as f:
        ...

Documentation

Test Plan

PR Quality Checklist

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

@k-boikov k-boikov added bug Something isn't working one-liner labels Apr 20, 2023
@Pwuts Pwuts changed the title Fix file opening error by getting current working directory Fix validate_json file error when cwd != project root Apr 21, 2023
@Pwuts Pwuts merged commit 91537b0 into Significant-Gravitas:stable Apr 21, 2023
@Pwuts
Copy link
Member

Pwuts commented Apr 21, 2023

So this merged into stable... I should have caught that and didn't, but just to be clear: PRs should be merged into master, NOT stable.

p-i- pushed a commit that referenced this pull request May 2, 2023
* Revert "Merge branch 'master' into stable"

This reverts commit c400897, reversing
changes made to fe855fe.

* Fix `validate_json` file error when cwd != project root (#2665)

Co-authored-by: qianchengliang <[email protected]>

* Revert "Revert "Merge branch 'master' into stable""

This reverts commit 999990b.

---------

Co-authored-by: BillSchumacher <[email protected]>
Co-authored-by: Mick <[email protected]>
Co-authored-by: qianchengliang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working one-liner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants