mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-23 15:48:11 +02:00
1. rename and modify plan to code plan and change
2. modify name of ActionNode instance
This commit is contained in:
parent
42565c39e3
commit
95ccd980f8
16 changed files with 101 additions and 91 deletions
|
|
@ -372,7 +372,7 @@ REFINED_TASKS_JSON = {
|
|||
"Anything UNCLEAR": "",
|
||||
}
|
||||
|
||||
PLAN_SAMPLE = {
|
||||
CODE_PLAN_AND_CHANGE_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'
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from openai._models import BaseModel
|
|||
|
||||
from metagpt.actions.action_node import ActionNode, dict_to_markdown
|
||||
from metagpt.actions.design_api import NEW_REQ_TEMPLATE
|
||||
from metagpt.actions.design_api_an import REFINED_DESIGN_NODES
|
||||
from metagpt.actions.design_api_an import REFINED_DESIGN_NODE
|
||||
from metagpt.llm import LLM
|
||||
from tests.data.incremental_dev_project.mock import (
|
||||
DESIGN_SAMPLE,
|
||||
|
|
@ -38,7 +38,7 @@ async def test_write_design_an(mocker):
|
|||
mocker.patch("metagpt.actions.design_api_an.REFINED_DESIGN_NODES.fill", return_value=root)
|
||||
|
||||
prompt = NEW_REQ_TEMPLATE.format(old_design=DESIGN_SAMPLE, context=dict_to_markdown(REFINED_PRD_JSON))
|
||||
node = await REFINED_DESIGN_NODES.fill(prompt, llm)
|
||||
node = await REFINED_DESIGN_NODE.fill(prompt, llm)
|
||||
|
||||
assert "Refined Implementation Approach" in node.instruct_content.model_dump()
|
||||
assert "Refined File list" in node.instruct_content.model_dump()
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from openai._models import BaseModel
|
|||
|
||||
from metagpt.actions.action_node import ActionNode, dict_to_markdown
|
||||
from metagpt.actions.project_management import NEW_REQ_TEMPLATE
|
||||
from metagpt.actions.project_management_an import REFINED_PM_NODES
|
||||
from metagpt.actions.project_management_an import REFINED_PM_NODE
|
||||
from metagpt.llm import LLM
|
||||
from tests.data.incremental_dev_project.mock import (
|
||||
REFINED_DESIGN_JSON,
|
||||
|
|
@ -38,7 +38,7 @@ async def test_project_management_an(mocker):
|
|||
mocker.patch("metagpt.actions.project_management_an.REFINED_PM_NODES.fill", return_value=root)
|
||||
|
||||
prompt = NEW_REQ_TEMPLATE.format(old_tasks=TASKS_SAMPLE, context=dict_to_markdown(REFINED_DESIGN_JSON))
|
||||
node = await REFINED_PM_NODES.fill(prompt, llm)
|
||||
node = await REFINED_PM_NODE.fill(prompt, llm)
|
||||
|
||||
assert "Refined Logic Analysis" in node.instruct_content.model_dump()
|
||||
assert "Refined Task list" in node.instruct_content.model_dump()
|
||||
|
|
|
|||
|
|
@ -10,16 +10,17 @@ from openai._models import BaseModel
|
|||
|
||||
from metagpt.actions.action_node import ActionNode
|
||||
from metagpt.actions.write_code import WriteCode
|
||||
from metagpt.actions.write_code_plan_an import (
|
||||
CODE_PLAN_CONTEXT,
|
||||
REFINED_CODE_TEMPLATE,
|
||||
WriteCodePlan,
|
||||
from metagpt.actions.write_code_plan_and_change_an import (
|
||||
CODE_PLAN_AND_CHANGE_CONTEXT,
|
||||
REFINED_TEMPLATE,
|
||||
WriteCodePlanAndChange,
|
||||
)
|
||||
from metagpt.actions.write_prd_an import REQUIREMENT_POOL
|
||||
from tests.data.incremental_dev_project.mock import (
|
||||
CODE_PLAN_AND_CHANGE_SAMPLE,
|
||||
DESIGN_SAMPLE,
|
||||
NEW_REQUIREMENT_SAMPLE,
|
||||
OLD_CODE_SAMPLE,
|
||||
PLAN_SAMPLE,
|
||||
REFINED_CODE_INPUT_SAMPLE,
|
||||
REFINED_CODE_SAMPLE,
|
||||
REFINED_DESIGN_JSON,
|
||||
|
|
@ -29,23 +30,23 @@ from tests.data.incremental_dev_project.mock import (
|
|||
)
|
||||
|
||||
|
||||
def mock_plan():
|
||||
return PLAN_SAMPLE
|
||||
def mock_code_plan_and_change():
|
||||
return CODE_PLAN_AND_CHANGE_SAMPLE
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_write_code_plan_an(mocker):
|
||||
root = ActionNode.from_children(
|
||||
"WriteCodePlan", [ActionNode(key="", expected_type=str, instruction="", example="")]
|
||||
"WriteCodePlanAndChange", [ActionNode(key="", expected_type=str, instruction="", example="")]
|
||||
)
|
||||
root.instruct_content = BaseModel()
|
||||
root.instruct_content.model_dump = mock_plan
|
||||
mocker.patch("metagpt.actions.write_code_plan_an.WriteCodePlan.run", return_value=root)
|
||||
root.instruct_content.model_dump = mock_code_plan_and_change
|
||||
mocker.patch("metagpt.actions.write_code_plan_an.WriteCodePlanAndChange.run", return_value=root)
|
||||
|
||||
write_code_plan = WriteCodePlan()
|
||||
context = CODE_PLAN_CONTEXT.format(
|
||||
write_code_plan = WriteCodePlanAndChange()
|
||||
context = CODE_PLAN_AND_CHANGE_CONTEXT.format(
|
||||
user_requirement=NEW_REQUIREMENT_SAMPLE,
|
||||
product_requirement_pools=REFINED_PRD_JSON.get("Refined Requirement Pool", ""),
|
||||
product_requirement_pools=REFINED_PRD_JSON.get(REQUIREMENT_POOL.key),
|
||||
design=REFINED_DESIGN_JSON,
|
||||
tasks=REFINED_TASKS_JSON,
|
||||
code=OLD_CODE_SAMPLE,
|
||||
|
|
@ -57,10 +58,10 @@ async def test_write_code_plan_an(mocker):
|
|||
|
||||
@pytest.mark.asyncio
|
||||
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(
|
||||
mocker.patch("metagpt.actions.write_code.WriteCodePlanAndChange.write_code", return_value=REFINED_CODE_SAMPLE)
|
||||
prompt = REFINED_TEMPLATE.format(
|
||||
user_requirement=NEW_REQUIREMENT_SAMPLE,
|
||||
plan=PLAN_SAMPLE,
|
||||
code_plan_and_change=CODE_PLAN_AND_CHANGE_SAMPLE,
|
||||
design=DESIGN_SAMPLE,
|
||||
tasks=TASKS_SAMPLE,
|
||||
code=REFINED_CODE_INPUT_SAMPLE,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import pytest
|
|||
from openai._models import BaseModel
|
||||
|
||||
from metagpt.actions.action_node import ActionNode
|
||||
from metagpt.actions.write_prd_an import REFINE_PRD_NODE, REFINE_PRD_TEMPLATE
|
||||
from metagpt.actions.write_prd_an import REFINED_PRD_NODE, REFINED_TEMPLATE
|
||||
from metagpt.llm import LLM
|
||||
from tests.data.incremental_dev_project.mock import (
|
||||
NEW_REQUIREMENT_SAMPLE,
|
||||
|
|
@ -34,12 +34,12 @@ async def test_write_prd_an(mocker):
|
|||
root.instruct_content.model_dump = mock_refined_prd_json
|
||||
mocker.patch("metagpt.actions.write_prd_an.REFINE_PRD_NODE.fill", return_value=root)
|
||||
|
||||
prompt = REFINE_PRD_TEMPLATE.format(
|
||||
prompt = REFINED_TEMPLATE.format(
|
||||
requirements=NEW_REQUIREMENT_SAMPLE,
|
||||
old_prd=PRD_SAMPLE,
|
||||
project_name="",
|
||||
)
|
||||
node = await REFINE_PRD_NODE.fill(prompt, llm)
|
||||
node = await REFINED_PRD_NODE.fill(prompt, llm)
|
||||
|
||||
assert "Refined Requirements" in node.instruct_content.model_dump()
|
||||
assert "Refined Product Goals" in node.instruct_content.model_dump()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue