Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

json/markdown format

femto0d9bbcb863a1
diff --git a/config/config.yaml b/config/config.yaml
index 444f55efd..17339eda5 100644
--- a/config/config.yaml
+++ b/config/config.yaml
@@ -84,4 +84,4 @@ MODEL_FOR_RESEARCHER_REPORT: gpt-3.5-turbo-16k
### browser path for pyppeteer engine, support Chrome, Chromium,MS Edge
#PYPPETEER_EXECUTABLE_PATH: "/usr/bin/google-chrome-stable"
-PROMPT_FORMAT: json #json or markdown
\ No newline at end of file
+PROMPT_FORMAT: markdown #json or markdown
\ No newline at end of file
diff --git a/metagpt/actions/design_api.py b/metagpt/actions/design_api.py
index af0ace497..f19fcbeaa 100644
--- a/metagpt/actions/design_api.py
+++ b/metagpt/actions/design_api.py
@@ -10,6 +10,7 @@ from pathlib import Path
from typing import List
from metagpt.actions import Action, ActionOutput
+from metagpt.config import CONFIG
from metagpt.const import WORKSPACE_ROOT
from metagpt.logs import logger
from metagpt.utils.common import CodeParser
@@ -201,10 +202,10 @@ class WriteDesign(Action):
await self._save_prd(docs_path, resources_path, context)
await self._save_system_design(docs_path, resources_path, system_design)
- async def run(self, context):
- prompt_template, format_example = get_template(templates)
+ async def run(self, context, format=CONFIG.prompt_format):
+ prompt_template, format_example = get_template(templates, format)
prompt = prompt_template.format(context=context, format_example=format_example)
# system_design = await self._aask(prompt)
- system_design = await self._aask_v1(prompt, "system_design", OUTPUT_MAPPING)
+ system_design = await self._aask_v1(prompt, "system_design", OUTPUT_MAPPING, format=format)
await self._save(context, system_design)
return system_design
diff --git a/metagpt/actions/project_management.py b/metagpt/actions/project_management.py
index bcaf85941..b395fa64e 100644
--- a/metagpt/actions/project_management.py
+++ b/metagpt/actions/project_management.py
@@ -8,6 +8,7 @@
from typing import List
from metagpt.actions.action import Action
+from metagpt.config import CONFIG
from metagpt.const import WORKSPACE_ROOT
from metagpt.utils.common import CodeParser
from metagpt.utils.get_template import get_template
@@ -177,10 +178,10 @@ class WriteTasks(Action):
requirements_path = WORKSPACE_ROOT / ws_name / "requirements.txt"
requirements_path.write_text("\n".join(rsp.instruct_content.dict().get("Required Python third-party packages")))
- async def run(self, context):
- prompt_template, format_example = get_template(templates)
+ async def run(self, context, format=CONFIG.prompt_format):
+ prompt_template, format_example = get_template(templates, format)
prompt = prompt_template.format(context=context, format_example=format_example)
- rsp = await self._aask_v1(prompt, "task", OUTPUT_MAPPING)
+ rsp = await self._aask_v1(prompt, "task", OUTPUT_MAPPING, format=format)
self._save(context, rsp)
return rsp
diff --git a/metagpt/actions/write_prd.py b/metagpt/actions/write_prd.py
index 42c9dd9d1..bd04ca79e 100644
--- a/metagpt/actions/write_prd.py
+++ b/metagpt/actions/write_prd.py
@@ -9,6 +9,7 @@ from typing import List
from metagpt.actions import Action, ActionOutput
from metagpt.actions.search_and_summarize import SearchAndSummarize
+from metagpt.config import CONFIG
from metagpt.logs import logger
from metagpt.utils.get_template import get_template
@@ -221,7 +222,7 @@ class WritePRD(Action):
def __init__(self, name="", context=None, llm=None):
super().__init__(name, context, llm)
- async def run(self, requirements, *args, **kwargs) -> ActionOutput:
+ async def run(self, requirements, format=CONFIG.prompt_format, *args, **kwargs) -> ActionOutput:
sas = SearchAndSummarize()
# rsp = await sas.run(context=requirements, system_text=SEARCH_AND_SUMMARIZE_SYSTEM_EN_US)
rsp = ""
@@ -230,11 +231,11 @@ class WritePRD(Action):
logger.info(sas.result)
logger.info(rsp)
- prompt_template, format_example = get_template(templates)
+ prompt_template, format_example = get_template(templates, format)
prompt = prompt_template.format(
requirements=requirements, search_information=info, format_example=format_example
)
logger.debug(prompt)
# prd = await self._aask_v1(prompt, "prd", OUTPUT_MAPPING)
- prd = await self._aask_v1(prompt, "prd", OUTPUT_MAPPING)
+ prd = await self._aask_v1(prompt, "prd", OUTPUT_MAPPING, format=format)
return prd
diff --git a/metagpt/config.py b/metagpt/config.py
index 2140334a6..53271133b 100644
--- a/metagpt/config.py
+++ b/metagpt/config.py
@@ -86,7 +86,7 @@ class Config(metaclass=Singleton):
self.mermaid_engine = self._get("MERMAID_ENGINE", "nodejs")
self.pyppeteer_executable_path = self._get("PYPPETEER_EXECUTABLE_PATH", "")
- self.prompt_format = self._get("PROMPT_FORMAT", "json")
+ self.prompt_format = self._get("PROMPT_FORMAT", "markdown")
def _init_with_config_files_and_env(self, configs: dict, yaml_file):
"""Load from config/key.yaml, config/config.yaml, and env in decreasing order of priority"""
diff --git a/metagpt/utils/get_template.py b/metagpt/utils/get_template.py
index e374188e0..86c1915f7 100644
--- a/metagpt/utils/get_template.py
+++ b/metagpt/utils/get_template.py
@@ -8,10 +8,10 @@
from metagpt.config import CONFIG
-def get_template(templates):
- selected_templates = templates.get(CONFIG.prompt_format)
+def get_template(templates, format=CONFIG.prompt_format):
+ selected_templates = templates.get(format)
if selected_templates is None:
- raise ValueError(f"Can't find {CONFIG.prompt_format} in passed in templates")
+ raise ValueError(f"Can't find {format} in passed in templates")
# Extract the selected templates
prompt_template = selected_templates["PROMPT_TEMPLATE"]