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

KeyError in apply_edits breaking improve mode #928

Closed
baldmanwithbeard opened this issue Dec 22, 2023 · 13 comments
Closed

KeyError in apply_edits breaking improve mode #928

baldmanwithbeard opened this issue Dec 22, 2023 · 13 comments
Labels
bug Something isn't working triage Interesting but stale issue. Will be close if inactive for 3 more days after label added.

Comments

@baldmanwithbeard
Copy link

I am running improve mode, creating c# and xaml. GPT Engineer is attempting to make updates to a xaml user control (here renamed to be "myExistingUserControl.xaml") and running into an issue where the filepath is invalid.


  File "<frozen runpy>", line 198, in _run_module_as_main

  File "<frozen runpy>", line 88, in _run_code

  File "C:\Users\asdf\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\Scripts\gpte.exe\__main__.py", line 7, in <module>
    sys.exit(app())
             ^^^^^

  File "C:\Users\asdf\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gpt_engineer\applications\cli\main.py", line 194, in main
    files_dict = agent.improve(files_dict, prompt)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "C:\Users\asdf\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gpt_engineer\applications\cli\cli_agent.py", line 131, in improve
    files_dict = self.improve_fn(
                 ^^^^^^^^^^^^^^^^

  File "C:\Users\asdf\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gpt_engineer\core\default\steps.py", line 182, in improve
    overwrite_code_with_edits(chat, files_dict)

  File "C:\Users\asdf\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gpt_engineer\core\chat_to_files.py", line 97, in overwrite_code_with_edits
    apply_edits(edits, files_dict)

  File "C:\Users\asdf\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gpt_engineer\core\chat_to_files.py", line 185, in apply_edits
    occurrences_cnt = files_dict[filename].count(edit.before)
                      ~~~~~~~~~~^^^^^^^^^^

KeyError: 'some/dir/myExistingUserControl.xaml'```
@baldmanwithbeard baldmanwithbeard added bug Something isn't working triage Interesting but stale issue. Will be close if inactive for 3 more days after label added. labels Dec 22, 2023
@baldmanwithbeard
Copy link
Author

Note: the "some/dir/" is not my edit for obscurity. i only changed the filename for this post. The "some/dir" path it is showing there is what it is actually showing.

ATheorell added a commit to ATheorell/gpt-engineer-dev that referenced this issue Dec 23, 2023
@ATheorell
Copy link
Collaborator

I made a potential fix in #930 . The cause of the problem is outlined in the PR. Would be awesome if you could pull the fix and see if it improves your case. I do not succeed in triggering the bug locally. Let me know how it goes.

@ATheorell
Copy link
Collaborator

Updated the fix #930 according to recommendation by @ErikBjare . Would be great if you can pull and play around @baldmanwithbeard

@baldmanwithbeard
Copy link
Author

Hi, I'm using the build I installed from pip; should this change be reflected there? Or is this on an unreleased build? (Do I need to pull the repo?)

@ATheorell
Copy link
Collaborator

Hi @baldmanwithbeard
I have not pushed the potential fix to main or released it to pypi yet, since I don't know if it leads to an improvement.
To test the fix, you need to clone the repo and checkout the PR commit. Here is how to do it:

clone gpt-engineer
go to the gpt-engineer repo with the terminal
fetch the fix branch with git fetch origin pull/930/head:new_branch_name
check out the branch with git checkout new_branch_name
poetry install
poetry shell

I hope this sketch is clear enough to get you started.

@baldmanwithbeard
Copy link
Author

poetry install step unsuccessful; keeps erroring with "cannot install jedi" and "cannot install sphinxcontrib-serializinghtml"

@baldmanwithbeard
Copy link
Author

I was still able to run "poetry shell" but then gpt-engineer was not a recognized command

@captivus
Copy link
Collaborator

Please paste the actual error output to assist us in assessing the issue.

@baldmanwithbeard
Copy link
Author

baldmanwithbeard commented Dec 28, 2023

On trying to run "poetry install":
image
and further down the line:
image

@captivus
Copy link
Collaborator

Thanks for the screenshots. Please create a Python virtual environment for your GPTE installation and give this another go. Here are instructions on how to do so. Should you encounter errors again, kindly paste text outputs of the same to save our furious fingers and the inevitable transcription errors that result.

miqueet added a commit to miqueet/gpt-engineer that referenced this issue Jan 3, 2024
I ran into issues where i was moving the file around and renaming it but renamed it back before i launched gpt engineer and ran into it an error because the file was not in the file_dict. This will address that. I am also making a comment in this issue gpt-engineer-org#928
@miqueet
Copy link

miqueet commented Jan 3, 2024

this is similar but not the same as my issue. I am submitting a PR for mine

I ran into issues where i was moving the file around and renaming it but renamed it back before i launched gpt engineer and ran into it an error because the file was not in the file_dict. This will address that. I am also making a comment in this issue. #952

@miqueet
Copy link

miqueet commented Jan 4, 2024

Hi @baldmanwithbeard I have not pushed the potential fix to main or released it to pypi yet, since I don't know if it leads to an improvement. To test the fix, you need to clone the repo and checkout the PR commit. Here is how to do it:

clone gpt-engineer go to the gpt-engineer repo with the terminal fetch the fix branch with git fetch origin pull/930/head:new_branch_name check out the branch with git checkout new_branch_name poetry install poetry shell

I hope this sketch is clear enough to get you started.

@captivus @ATheorell I just wanted to let you know this worked for me, checking out the new version.

I did run into an error unrelated to this issue but it does look the program was trying to edit a block that had already been edited and doesn't see the expected code block and errors out.
WARNING:gpt_engineer.core.chat_to_files:While applying an edit to VMClone.ps1, the code block to be replaced was not found. No instances will be replaced.

ATheorell added a commit to ATheorell/gpt-engineer-dev that referenced this issue Jan 5, 2024
ATheorell added a commit that referenced this issue Jan 5, 2024
potential fix for some/dir/ bug #928
@ATheorell
Copy link
Collaborator

Thanks for checking @Wheaties466

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Interesting but stale issue. Will be close if inactive for 3 more days after label added.
Projects
None yet
Development

No branches or pull requests

4 participants