output code_steps to json

This commit is contained in:
lidanyang 2023-12-06 17:31:51 +08:00
parent 56dd0ee882
commit 21d97a23bb
3 changed files with 15 additions and 13 deletions

View file

@ -153,7 +153,6 @@ class WriteCodeWithTools(BaseWriteAnalysisCode):
context: List[Message],
plan: Plan = None,
code_steps: str = "",
data_desc: str = "",
) -> str:
task_type = plan.current_task.task_type
available_tools = registry.get_all_schema_by_module(task_type)

View file

@ -4,18 +4,12 @@ from typing import Dict, List, Union
from metagpt.actions import Action
from metagpt.schema import Message, Task, Plan
from metagpt.utils.common import CodeParser
CODE_STEPS_PROMPT_TEMPLATE = """
# Context
{context}
## Format example
1.
2.
3.
...
-----
Tasks are all code development tasks.
You are a professional engineer, the main goal is to plan out concise solution steps for Current Task before coding.
@ -25,7 +19,16 @@ The output plan should following the subsequent principles:
1.The plan is a rough checklist of steps outlining the entire program's structure.Try to keep the number of steps fewer than 5.
2.The steps should be written concisely and at a high level, avoiding overly detailed implementation specifics.
3.The execution of the plan happens sequentially, but the plan can incorporate conditional (if) and looping(loop) keywords for more complex structures.
4.Output carefully referenced "Format example" in format.
Output the code steps in a JSON format, as shown in this example:
```json
{
"Step 1": "",
"Step 2": "",
"Step 3": "",
...
}
```
"""
STRUCTURAL_CONTEXT = """
@ -51,10 +54,11 @@ class WriteCodeSteps(Action):
"""
context = self.get_context(plan)
code_steps_prompt = CODE_STEPS_PROMPT_TEMPLATE.format(
context=context,
code_steps_prompt = CODE_STEPS_PROMPT_TEMPLATE.replace(
"{context}", context
)
code_steps = await self._aask(code_steps_prompt)
code_steps = CodeParser.parse_code(block=None, text=code_steps)
return code_steps
def get_context(self, plan: Plan):
@ -74,4 +78,3 @@ class WriteCodeSteps(Action):
)
# print(context)
return context