mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-02 20:32:38 +02:00
Update the editor parameters and enhance the engineer experience.
This commit is contained in:
parent
384dc78e70
commit
726dc65067
4 changed files with 103 additions and 72 deletions
|
|
@ -956,14 +956,15 @@ I have opened the openai_api.py file. However, the range of lines shown is from
|
|||
```
|
||||
|
||||
## example 9
|
||||
I've found the bug and will start fixing it. I'll pay close attention to the indentation.
|
||||
I want to change the key bindings from (w/s) to the arrow keys (up, down). And add the space bar to pause.
|
||||
the previous file look like:
|
||||
739| can_fold_brackets = self._settings['fold_func_brackets'] and \
|
||||
740| len(args) == 1 and \
|
||||
741| not self._needs_function_brackets(expr.args[0])
|
||||
742| inv_trig_table = ["asin", "acos", "atan", "acsc", "asec", "acot"]
|
||||
743| # If the function is an inverse trig function, handle the style
|
||||
Since I only need to modify a few lines in this file, I will use Editor.edit_file_by_replace. The original content will be replaced by the new code.
|
||||
142| while not self.is_game_over():
|
||||
143| if event.key == pygame.K_w:
|
||||
144| self.move_up()
|
||||
145| elif event.key == pygame.K_s:
|
||||
146| self.move_down()
|
||||
147| self.add_random_tile()
|
||||
Since I only need to modify the lines 143 to 146, I will use Editor.edit_file_by_replace. The original content will be replaced by the new code.
|
||||
Editor tool is exclusive. If I use this tool, I cannot use any other commands in the current response.
|
||||
```json
|
||||
[
|
||||
|
|
@ -971,46 +972,47 @@ Editor tool is exclusive. If I use this tool, I cannot use any other commands in
|
|||
"command_name": "Editor.edit_file_by_replace",
|
||||
"args": {
|
||||
"file_name":"/workspace/MetaGPT/provider/openai_api.py",
|
||||
"start_line": 742,
|
||||
"end_line": 742,
|
||||
"new_content": " inv_trig_table = ["asin", "acos", "atan", "acsc", "asec", "acot"]"
|
||||
}
|
||||
"start_line_number": 143,
|
||||
"start_line_content":" if event.key == pygame.K_w:",
|
||||
"new_content": " if event.key == pygame.K_UP:\\n self.move_up()\\n elif event.key == pygame.K_DOWN:\\n self.move_down()\\n elif event.key == pygame.K_SPACE:\\n self.stop()"
|
||||
"end_line_number": 146,
|
||||
"end_line_content": " self.move_down()",
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
## example 10
|
||||
I want to add a score variable in the initialization of the game.
|
||||
the previous file look like:
|
||||
028| if restart:
|
||||
029| self.snake = Snake()
|
||||
030| self.food = Food(self.board_size)
|
||||
031| self.start_game()
|
||||
032| self.location = (0,0)
|
||||
I only need to add a few lines to the file, so I will use Editor.insert_content_at_line. The new code will not cover the original code.
|
||||
Note that the Editor command must be executed in a single response, so this step will only involve using the Editor command.
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"command_name": "Editor.insert_content_at_line",
|
||||
"args": {
|
||||
"file_name":"/workspace/MetaGPT/provider/openai_api.py"
|
||||
"line_number":727,
|
||||
"content": "if hasattr(self, '_print_' + func) and not isinstance(expr.func, UndefinedFunction):\\n return getattr(self, '_print_' + func)(expr, exp)"
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
"line_number":31,
|
||||
"insert_content": " self.score = Score()"
|
||||
|
||||
## example 10.1
|
||||
To enhance the functionality of the 2048 game, including game end detection and score tracking, we need to add these features to the existing game_2048.py file. First, we will add a score tracking feature, and then we will insert game end detection logic into the game loop.
|
||||
We will use the Editor.insert_content_at_line command to insert new code into the file for adding score tracking and game end detection.
|
||||
Since Editor.insert_content_at_line can only be used once per response, this time I will use it to create the variable self.score
|
||||
```json
|
||||
[
|
||||
{
|
||||
"command_name": "Editor.insert_content_at_line",
|
||||
"args": {
|
||||
"file_name": "/home/mgx/mgx/MetaGPT/workspace/2048_game_py/game_2048.py",
|
||||
"line_number": 4,
|
||||
"content": " self.score = 0\n"
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
After executing the command, the file will be:
|
||||
028| if restart:
|
||||
029| self.snake = Snake()
|
||||
030| self.food = Food(self.board_size)
|
||||
031| self.score = Score()
|
||||
032| self.start_game()
|
||||
033| self.location = (0,0)
|
||||
In the next turn, I will try to add another code snippet
|
||||
|
||||
## example 11
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue