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 sending changes back to rework if nothing got applied. #676

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions pilot/helpers/agents/CodeMonkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from helpers.Agent import Agent
from helpers.files import get_file_contents
from const.function_calls import GET_FILE_TO_MODIFY, REVIEW_CHANGES
from logger.logger import logger

from utils.exit import trace_code_event
from utils.telemetry import telemetry
Expand Down Expand Up @@ -268,17 +269,27 @@ def review_change(

if len(hunks_to_apply) == len(hunks):
print("Applying entire change")
logger.info(f"Applying entire change to {file_name}")
return new_content, None

elif len(hunks_to_apply) == 0:
print(f"Rejecting entire change with reason: {llm_response['review_notes']}")
# If everything can be safely ignoring, it's probably because the files already implement the changes
# from previous tasks (which can happen often). Insisting on a change here is likely to cause problems.
return old_content, None
if hunks_to_rework:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're not always sending the review_log because it is always non-empty (because it includes review_notes). If we applied nothing and asked to rework, we need the log, otherwise if we applied nothing and ignored everything (asked nothing for rework), we don't want for the code monkey to rework it.

print(f"Requesting rework for {len(hunks_to_rework)} changes with reason: {llm_response['review_notes']}")
logger.info(f"Requesting rework for {len(hunks_to_rework)} changes to {file_name} (0 hunks to apply)")
return old_content, review_log
else:
# If everything can be safely ignored, it's probably because the files already implement the changes
# from previous tasks (which can happen often). Insisting on a change here is likely to cause problems.
print(f"Rejecting entire change with reason: {llm_response['review_notes']}")
logger.info(f"Rejecting entire change to {file_name} with reason: {llm_response['review_notes']}")
return old_content, None

print("Applying code change:\n" + diff_log)
logger.info(f"Applying code change to {file_name}:\n{diff_log}")
new_content = self.apply_diff(file_name, old_content, hunks_to_apply, new_content)
if hunks_to_rework:
print(f"Requesting rework for {len(hunks_to_rework)} changes with reason: {llm_response['review_notes']}")
logger.info(f"Requesting further rework for {len(hunks_to_rework)} changes to {file_name}")
return new_content, review_log
else:
return new_content, None
Expand Down
5 changes: 4 additions & 1 deletion pilot/prompts/development/implement_changes.prompt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ the full contents of the updated file, without skipping over any content
```
------------------------end_of_format---------------------------

**IMPORTANT**:If the instructions have comments like `// ..add code here...` or `# placeholder for code`, instead of copying the comment, interpret the instructions and output the relevant code.

**IMPORTANT**: Your reply MUST NOT omit any code in the new implementation or substitute anything with comments like `// .. rest of the code goes here ..` or `# insert existing code here`, because I will overwrite the existing file with the content you provide. Output ONLY the content for this file, without additional explanation, suggestions or notes. Your output MUST start with ``` and MUST end with ``` and include only the complete file contents.
**IMPORTANT**: If the user must configure something manually, mark the line that needs user configuration with `INPUT_REQUIRED {input_description}` comment, where `input_description` is a description of what needs to be added here by the user. Use appropriate syntax for comments in the file you're saving (for example `// INPUT_REQUIRED {input_description}` in JavaScript). If the file type doesn't support comments (eg JSON), don't add any.

**IMPORTANT**: For hardcoded configuration values that the user needs to change, mark the line that needs user configuration with `INPUT_REQUIRED {config_description}` comment, where `config_description` is a description of the value that needs to be set by the user. Use appropriate syntax for comments in the file you're saving (for example `// INPUT_REQUIRED {config_description}` in JavaScript). NEVER ask the user to write code or provide implementation, even if the instructions suggest it! If the file type doesn't support comments (eg JSON), don't add any.

{{ logs_and_error_handling }}