mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-07-02 16:01:04 +02:00
1. rename and modify guideline to plan
2. update prompt in ActionNode 3. add code comment 4. refactor Guideline code structure
This commit is contained in:
parent
6fb48664cb
commit
5190dc4462
11 changed files with 112 additions and 186 deletions
|
|
@ -372,8 +372,8 @@ REFINED_TASKS_JSON = {
|
|||
"Anything UNCLEAR": "",
|
||||
}
|
||||
|
||||
GUIDELINES_AND_INCREMENTAL_CHANGE_SAMPLE = {
|
||||
"Guidelines and Incremental Change": '\n1. Guideline for gui.py: Develop the GUI using Tkinter to replace the command-line interface. Start by setting up the main window and event handling. Then, add widgets for displaying the game status, results, and feedback. Implement interactive elements for difficulty selection and visualize the guess history. Finally, create animations for guess feedback and ensure responsiveness across different screen sizes.\n```python\nclass GUI:\n- pass\n+ def __init__(self):\n+ self.setup_window()\n+\n+ def setup_window(self):\n+ # Initialize the main window using Tkinter\n+ pass\n+\n+ def bind_events(self):\n+ # Bind button clicks and other events\n+ pass\n+\n+ def update_feedback(self, message: str):\n+ # Update the feedback label with the given message\n+ pass\n+\n+ def update_attempts(self, attempts: int):\n+ # Update the attempts label with the number of attempts\n+ pass\n+\n+ def update_history(self, history: list):\n+ # Update the history view with the list of past guesses\n+ pass\n+\n+ def show_difficulty_selector(self):\n+ # Show buttons or a dropdown for difficulty selection\n+ pass\n+\n+ def animate_guess_result(self, correct: bool):\n+ # Trigger an animation for correct or incorrect guesses\n+ pass\n```\n\n2. Guideline for main.py: Modify the main.py to initialize the GUI and start the event-driven game loop. Ensure that the GUI is the primary interface for user interaction.\n```python\nclass Main:\n def main(self):\n- user_interface = UI()\n- user_interface.start()\n+ graphical_user_interface = GUI()\n+ graphical_user_interface.setup_window()\n+ graphical_user_interface.bind_events()\n+ # Start the Tkinter main loop\n+ pass\n\n if __name__ == "__main__":\n main_instance = Main()\n main_instance.main()\n```\n\n3. Guideline for ui.py: Refactor ui.py to work with the new GUI class. Remove command-line interactions and delegate display and input tasks to the GUI.\n```python\nclass UI:\n- def display_message(self, message: str):\n- print(message)\n+\n+ def display_message(self, message: str):\n+ # This method will now pass the message to the GUI to display\n+ pass\n\n- def get_user_input(self, prompt: str) -> str:\n- return input(prompt)\n+\n+ def get_user_input(self, prompt: str) -> str:\n+ # This method will now trigger the GUI to get user input\n+ pass\n\n- def show_attempts(self, attempts: int):\n- print(f"Number of attempts: {attempts}")\n+\n+ def show_attempts(self, attempts: int):\n+ # This method will now update the GUI with the number of attempts\n+ pass\n\n- def show_history(self, history: list):\n- print("Guess history:")\n- for guess in history:\n- print(guess)\n+\n+ def show_history(self, history: list):\n+ # This method will now update the GUI with the guess history\n+ pass\n```\n\n4. Guideline for game.py: Ensure game.py remains mostly unchanged as it contains the core game logic. However, make minor adjustments if necessary to integrate with the new GUI.\n```python\nclass Game:\n # No changes required for now\n```\n'
|
||||
PLAN_SAMPLE = {
|
||||
"Plan": '\n1. Plan for gui.py: Develop the GUI using Tkinter to replace the command-line interface. Start by setting up the main window and event handling. Then, add widgets for displaying the game status, results, and feedback. Implement interactive elements for difficulty selection and visualize the guess history. Finally, create animations for guess feedback and ensure responsiveness across different screen sizes.\n```python\nclass GUI:\n- pass\n+ def __init__(self):\n+ self.setup_window()\n+\n+ def setup_window(self):\n+ # Initialize the main window using Tkinter\n+ pass\n+\n+ def bind_events(self):\n+ # Bind button clicks and other events\n+ pass\n+\n+ def update_feedback(self, message: str):\n+ # Update the feedback label with the given message\n+ pass\n+\n+ def update_attempts(self, attempts: int):\n+ # Update the attempts label with the number of attempts\n+ pass\n+\n+ def update_history(self, history: list):\n+ # Update the history view with the list of past guesses\n+ pass\n+\n+ def show_difficulty_selector(self):\n+ # Show buttons or a dropdown for difficulty selection\n+ pass\n+\n+ def animate_guess_result(self, correct: bool):\n+ # Trigger an animation for correct or incorrect guesses\n+ pass\n```\n\n2. Plan for main.py: Modify the main.py to initialize the GUI and start the event-driven game loop. Ensure that the GUI is the primary interface for user interaction.\n```python\nclass Main:\n def main(self):\n- user_interface = UI()\n- user_interface.start()\n+ graphical_user_interface = GUI()\n+ graphical_user_interface.setup_window()\n+ graphical_user_interface.bind_events()\n+ # Start the Tkinter main loop\n+ pass\n\n if __name__ == "__main__":\n main_instance = Main()\n main_instance.main()\n```\n\n3. Plan for ui.py: Refactor ui.py to work with the new GUI class. Remove command-line interactions and delegate display and input tasks to the GUI.\n```python\nclass UI:\n- def display_message(self, message: str):\n- print(message)\n+\n+ def display_message(self, message: str):\n+ # This method will now pass the message to the GUI to display\n+ pass\n\n- def get_user_input(self, prompt: str) -> str:\n- return input(prompt)\n+\n+ def get_user_input(self, prompt: str) -> str:\n+ # This method will now trigger the GUI to get user input\n+ pass\n\n- def show_attempts(self, attempts: int):\n- print(f"Number of attempts: {attempts}")\n+\n+ def show_attempts(self, attempts: int):\n+ # This method will now update the GUI with the number of attempts\n+ pass\n\n- def show_history(self, history: list):\n- print("Guess history:")\n- for guess in history:\n- print(guess)\n+\n+ def show_history(self, history: list):\n+ # This method will now update the GUI with the guess history\n+ pass\n```\n\n4. Plan for game.py: Ensure game.py remains mostly unchanged as it contains the core game logic. However, make minor adjustments if necessary to integrate with the new GUI.\n```python\nclass Game:\n # No changes required for now\n```\n'
|
||||
}
|
||||
|
||||
REFINED_CODE_INPUT_SAMPLE = """
|
||||
|
|
|
|||
|
|
@ -3,23 +3,23 @@
|
|||
"""
|
||||
@Time : 2024/01/03
|
||||
@Author : mannaandpoem
|
||||
@File : test_write_code_guideline_an.py
|
||||
@File : test_write_code_plan_an.py
|
||||
"""
|
||||
import pytest
|
||||
from openai._models import BaseModel
|
||||
|
||||
from metagpt.actions.action_node import ActionNode
|
||||
from metagpt.actions.write_code import WriteCode
|
||||
from metagpt.actions.write_code_guideline_an import (
|
||||
CODE_GUIDELINE_CONTEXT,
|
||||
from metagpt.actions.write_code_plan_an import (
|
||||
CODE_PLAN_CONTEXT,
|
||||
REFINED_CODE_TEMPLATE,
|
||||
WriteCodeGuideline,
|
||||
WriteCodePlan,
|
||||
)
|
||||
from tests.data.incremental_dev_project.mock import (
|
||||
DESIGN_SAMPLE,
|
||||
GUIDELINES_AND_INCREMENTAL_CHANGE_SAMPLE,
|
||||
NEW_REQUIREMENT_SAMPLE,
|
||||
OLD_CODE_SAMPLE,
|
||||
PLAN_SAMPLE,
|
||||
REFINED_CODE_INPUT_SAMPLE,
|
||||
REFINED_CODE_SAMPLE,
|
||||
REFINED_DESIGN_JSON,
|
||||
|
|
@ -29,30 +29,30 @@ from tests.data.incremental_dev_project.mock import (
|
|||
)
|
||||
|
||||
|
||||
def mock_guidelines_and_incremental_change():
|
||||
return GUIDELINES_AND_INCREMENTAL_CHANGE_SAMPLE
|
||||
def mock_plan():
|
||||
return PLAN_SAMPLE
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_write_code_guideline_an(mocker):
|
||||
async def test_write_code_plan_an(mocker):
|
||||
root = ActionNode.from_children(
|
||||
"WriteCodeGuideline", [ActionNode(key="", expected_type=str, instruction="", example="")]
|
||||
"WriteCodePlan", [ActionNode(key="", expected_type=str, instruction="", example="")]
|
||||
)
|
||||
root.instruct_content = BaseModel()
|
||||
root.instruct_content.model_dump = mock_guidelines_and_incremental_change
|
||||
mocker.patch("metagpt.actions.write_code_guideline_an.WriteCodeGuideline.run", return_value=root)
|
||||
root.instruct_content.model_dump = mock_plan
|
||||
mocker.patch("metagpt.actions.write_code_plan_an.WriteCodePlan.run", return_value=root)
|
||||
|
||||
write_code_guideline = WriteCodeGuideline()
|
||||
context = CODE_GUIDELINE_CONTEXT.format(
|
||||
write_code_plan = WriteCodePlan()
|
||||
context = CODE_PLAN_CONTEXT.format(
|
||||
user_requirement=NEW_REQUIREMENT_SAMPLE,
|
||||
product_requirement_pools=REFINED_PRD_JSON.get("Refined Requirement Pool", ""),
|
||||
design=REFINED_DESIGN_JSON,
|
||||
tasks=REFINED_TASKS_JSON,
|
||||
code=OLD_CODE_SAMPLE,
|
||||
)
|
||||
node = await write_code_guideline.run(context=context)
|
||||
node = await write_code_plan.run(context=context)
|
||||
|
||||
assert "Guidelines and Incremental Change" in node.instruct_content.model_dump()
|
||||
assert "Plan" in node.instruct_content.model_dump()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -60,7 +60,7 @@ async def test_refine_code(mocker):
|
|||
mocker.patch("metagpt.actions.write_code.WriteCode.write_code", return_value=REFINED_CODE_SAMPLE)
|
||||
prompt = REFINED_CODE_TEMPLATE.format(
|
||||
user_requirement=NEW_REQUIREMENT_SAMPLE,
|
||||
guideline=GUIDELINES_AND_INCREMENTAL_CHANGE_SAMPLE,
|
||||
plan=PLAN_SAMPLE,
|
||||
design=DESIGN_SAMPLE,
|
||||
tasks=TASKS_SAMPLE,
|
||||
code=REFINED_CODE_INPUT_SAMPLE,
|
||||
|
|
@ -105,7 +105,7 @@ def log_and_check_result(result, tag_name="refine"):
|
|||
|
||||
def get_incremental_dev_result(idea, project_name, use_review=True):
|
||||
project_path = TEST_DATA_PATH / "incremental_dev_project" / project_name
|
||||
if not os.path.exists(project_path):
|
||||
if project_path.exists():
|
||||
raise Exception(f"Project {project_name} not exists")
|
||||
check_or_create_base_tag(project_path)
|
||||
args = [idea, "--inc", "--project-path", project_path]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue