gpt-engineer icon indicating copy to clipboard operation
gpt-engineer copied to clipboard

ValueError: Could not parse following text as code edit:

Open RiccardoRomagnoli opened this issue 2 years ago • 4 comments

Expected Behavior

Improve the code

Current Behavior

Error gets thrown

Failure Information

Traceback (most recent call last):

File "/home/riccardo/.local/bin/gpt-engineer", line 8, in sys.exit(app())

File "/home/riccardo/.local/lib/python3.10/site-packages/gpt_engineer/cli/main.py", line 169, in main messages = step(ai, dbs)

File "/home/riccardo/.local/lib/python3.10/site-packages/gpt_engineer/core/steps.py", line 588, in improve_existing_code overwrite_files_with_edits(messages[-1].content.strip(), dbs)

File "/home/riccardo/.local/lib/python3.10/site-packages/gpt_engineer/core/chat_to_files.py", line 219, in overwrite_files_with_edits edits = parse_edits(chat)

File "/home/riccardo/.local/lib/python3.10/site-packages/gpt_engineer/core/chat_to_files.py", line 268, in parse_edits return parse_all_edits(llm_response)

File "/home/riccardo/.local/lib/python3.10/site-packages/gpt_engineer/core/chat_to_files.py", line 255, in parse_all_edits edits.append(parse_one_edit(current_edit))

File "/home/riccardo/.local/lib/python3.10/site-packages/gpt_engineer/core/chat_to_files.py", line 240, in parse_one_edit raise ValueError(f"Could not parse following text as code edit: \n{text}")

Steps to Reproduce

I'm using this prompt:

Improve Code for Readability and Reusability:

Refactor complex functions into smaller, more manageable pieces. Use meaningful variable and function names that clearly indicate their purpose. Follow a consistent coding style and adhere to best practices outlined in the project's style guide. Implement design patterns where applicable to promote code reusability. Implement TODOs Where Appropriate:

Review the codebase for any // TODO: comments and prioritize their completion based on the project's goals. Assess the impact of each TODO on the current codebase and potential future developments. Document the reasoning behind the resolution of TODOs for future reference. Add Comments Where Appropriate:

Provide clear and concise comments for complex code blocks to explain the logic and its purpose. Update or remove outdated comments that no longer reflect the current state of the code. Use comments to outline the steps of complex algorithms or workflows within the code.

Optimize Performance:

Identify bottlenecks and optimize critical sections of the code for better performance. Consider the time and space complexity of algorithms and refactor if more efficient solutions exist. Utilize profiling tools to measure performance improvements. Enhance Security:

Review the code for potential security vulnerabilities and apply best practices to mitigate risks. Ensure that all sensitive data is properly encrypted and that secure coding principles are followed. Stay updated with the latest security advisories and apply patches or updates as necessary.

Implement Unit Tests and Integration Tests:

Write unit tests for new features and bug fixes to validate individual components. Create integration tests to ensure that different parts of the application work together as expected. Strive for a high level of test coverage to catch potential issues early.

Also, I got charged :'( image

RiccardoRomagnoli avatar Nov 07 '23 21:11 RiccardoRomagnoli

I believe this could be loosely related to #814 in that the diff head sections of the diffs are not completely clean.

ATheorell avatar Nov 08 '23 18:11 ATheorell

I do get the same error : raise ValueError(f"Could not parse following text as code edit: \n{text}")

LRpz avatar Dec 02 '23 07:12 LRpz

I do get the same error : raise ValueError(f"Could not parse following text as code edit: \n{text}")

Thanks for reporting. We are working on a solution to make code improve more reliable.

ATheorell avatar Dec 03 '23 15:12 ATheorell

For clarification, it happened after specifically asking to refactor a long python file into smaller ones, and I believe the edit structure ('>>>>' ...) wasn't part of the newly generated files making the function raise the error.

LRpz avatar Dec 03 '23 18:12 LRpz

@ATheorell any up?

RiccardoRomagnoli avatar Jan 12 '24 08:01 RiccardoRomagnoli

@RiccardoRomagnoli

I'm looking at implementing https://github.com/gpt-engineer-org/gpt-engineer/issues/869 together with @similato87 to improve on this front. If you are interested in joining this effort, you are more than welcome.

ATheorell avatar Jan 13 '24 12:01 ATheorell

I get the same error, basically unable to use the improvement as it errors out in the middle :

ValueError: Could not parse following text as code edit

Chemformalixer avatar Jan 13 '24 21:01 Chemformalixer

Hello @RiccardoRomagnoli, @LRpz, @Chemformalixer, I'm thrilled to share that we've developed a solid approach to addressing these challenges. @ATheorell and I have rigorously tested it across a range of parsing tasks, and the results with the GPT-engineer are promising. Moreover, for tasks that surpass the capabilities of existing LLMs, our project will ensure accurate change instructions, providing an opportunity for you to optimize your token usage. No waste token anymore :) @RiccardoRomagnoli.

similato87 avatar Feb 19 '24 04:02 similato87

Great! This is very exciting news. Do you know when you'd like to release the update?

LRpz avatar Feb 19 '24 06:02 LRpz

It is already released in the main branch. Release on pip will follow in a few days to allow for potential feedback @LRpz

ATheorell avatar Feb 19 '24 06:02 ATheorell