gpt-engineer
gpt-engineer copied to clipboard
KeyError in apply_edits breaking improve mode
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'```
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.
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.
Updated the fix #930 according to recommendation by @ErikBjare . Would be great if you can pull and play around @baldmanwithbeard
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?)
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.
poetry install step unsuccessful; keeps erroring with "cannot install jedi" and "cannot install sphinxcontrib-serializinghtml"
I was still able to run "poetry shell" but then gpt-engineer was not a recognized command
Please paste the actual error output to assist us in assessing the issue.
On trying to run "poetry install":
and further down the line:
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.
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. https://github.com/gpt-engineer-org/gpt-engineer/pull/952
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.
Thanks for checking @Wheaties466