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

Two Step Edits #530

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
add rewrite file prompt
  • Loading branch information
biobootloader committed Feb 24, 2024
commit 76c1be0829c4353562e41a9ec1bfaa8b6e1d0264
11 changes: 11 additions & 0 deletions mentat/resources/prompts/two_step_edit_prompt_rewrite_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
You are part of an expert AI coding system.

In the next message you will be given the contents of a code file. The user will then specify some edits to be made to the file.

Your response should:
- rewrite the entire file, including all the requested edits
- wrap your entire response in ```python ... ``` to format it as Python code
- do not include anything else in your response other than the wrapped code
- do not make any other changes to the code other than the requested edits
- even formatting changes should not be made unless explicitly requested by the user
- if a change is not fully specified, do your best to follow the spirit of what was asked
12 changes: 11 additions & 1 deletion mentat/stream_model_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

two_step_edit_prompt_filename = Path("two_step_edit_prompt.txt")
two_step_edit_prompt_list_files_filename = Path("two_step_edit_prompt_list_files.txt")
two_step_edit_prompt_rewrite_file_filename = Path(
"two_step_edit_prompt_rewrite_file.txt"
)


async def stream_model_response(
Expand Down Expand Up @@ -96,6 +99,10 @@ def get_two_step_list_files_prompt() -> str:
return read_prompt(two_step_edit_prompt_list_files_filename)


def get_two_step_rewrite_file_prompt() -> str:
return read_prompt(two_step_edit_prompt_rewrite_file_filename)


async def stream_model_response_two_step(
Copy link
Contributor

Choose a reason for hiding this comment

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

The stream_model_response_two_step function contains several TODO comments that suggest incomplete implementation, such as handling interrupts, tracking costs of all calls, and logging API calls. It's crucial to address these TODOs before merging this feature into the main branch to ensure the two-step edit process is fully functional and robust.

messages: list[ChatCompletionMessageParam],
) -> ParsedLLMResponse:
Expand Down Expand Up @@ -167,7 +174,10 @@ async def stream_model_response_two_step(
stream.send("Error processing model response: Invalid JSON", style="error")
# TODO: handle error

stream.send(f"\n\n{response_json}\n\n")
stream.send(f"\n{response_json}\n")

# for file_path in response_json["files"]:
# rewrite_file_messages: list[ChatCompletionMessageParam] = [

# async with parser.interrupt_catcher():
# parsed_llm_response = await parser.stream_and_parse_llm_response(
Expand Down
Loading