mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-05 14:55:18 +02:00
fix test
This commit is contained in:
parent
dd8be8a382
commit
2846a462a0
4 changed files with 24 additions and 12 deletions
|
|
@ -77,10 +77,13 @@ class Action(ABC):
|
|||
logger.debug(content)
|
||||
output_class = ActionOutput.create_model_class(output_class_name, output_data_mapping)
|
||||
|
||||
pattern = r"\[CONTENT\](.+?)\[/CONTENT\]"
|
||||
pattern = r"\[CONTENT\](\s*\{.*?\}\s*)\[/CONTENT\]"
|
||||
matches = re.findall(pattern, content, re.DOTALL)
|
||||
|
||||
# Use re.findall to extract content between the tags
|
||||
extracted_content = re.search(pattern, content, re.DOTALL).group(1)
|
||||
for match in matches:
|
||||
if match:
|
||||
extracted_content = match
|
||||
break
|
||||
|
||||
parsed_data = CustomDecoder(strict=False).decode(extracted_content)
|
||||
logger.debug(parsed_data)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ Max Output: 8192 chars or 2048 tokens. Try to use them up.
|
|||
|
||||
## Anything UNCLEAR: Provide as Plain text. Make clear here.
|
||||
|
||||
Your job is to create a properly formatted JSON, wrapped inside [CONTENT][/CONTENT] like format example
|
||||
output a properly formatted JSON, wrapped inside [CONTENT][/CONTENT] like format example,
|
||||
and only output the json inside this tag, nothing else
|
||||
"""
|
||||
FORMAT_EXAMPLE = """
|
||||
[CONTENT]
|
||||
|
|
@ -92,8 +93,10 @@ class WriteDesign(Action):
|
|||
|
||||
def _save_prd(self, docs_path, resources_path, context):
|
||||
prd_file = docs_path / "prd.md"
|
||||
quadrant_chart = context[-1].instruct_content.dict()["Competitive Quadrant Chart"]
|
||||
mermaid_to_file(quadrant_chart, resources_path / "competitive_analysis")
|
||||
if context[-1].instruct_content and context[-1].instruct_content.dict()["Competitive Quadrant Chart"]:
|
||||
quadrant_chart = context[-1].instruct_content.dict()["Competitive Quadrant Chart"]
|
||||
mermaid_to_file(quadrant_chart, resources_path / "competitive_analysis")
|
||||
|
||||
logger.info(f"Saving PRD to {prd_file}")
|
||||
prd_file.write_text(context[-1].content)
|
||||
|
||||
|
|
@ -125,7 +128,10 @@ class WriteDesign(Action):
|
|||
self._save_system_design(docs_path, resources_path, system_design)
|
||||
|
||||
async def run(self, context):
|
||||
prompt = PROMPT_TEMPLATE.format(context=context, format_example=FORMAT_EXAMPLE)
|
||||
if isinstance(context, ActionOutput):
|
||||
prompt = PROMPT_TEMPLATE.format(context=context.content, format_example=FORMAT_EXAMPLE)
|
||||
else: # context is a string
|
||||
prompt = PROMPT_TEMPLATE.format(context=context, format_example=FORMAT_EXAMPLE)
|
||||
# system_design = await self._aask(prompt)
|
||||
system_design = await self._aask_json_v1(prompt, "system_design", OUTPUT_MAPPING)
|
||||
self._save(context, system_design)
|
||||
|
|
|
|||
|
|
@ -61,7 +61,8 @@ Requirements: According to the context, fill in the following missing informatio
|
|||
## UI Design draft: Provide as Plain text. Be simple. Describe the elements and functions, also provide a simple style description and layout description.
|
||||
## Anything UNCLEAR: Provide as Plain text. Make clear here.
|
||||
|
||||
Your job is to create a properly formatted JSON, wrapped inside [CONTENT][/CONTENT] like format example,output CONTENT json directly
|
||||
output a properly formatted JSON, wrapped inside [CONTENT][/CONTENT] like format example,
|
||||
and only output the json inside this tag, nothing else
|
||||
"""
|
||||
FORMAT_EXAMPLE = """
|
||||
[CONTENT]
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
"""
|
||||
import pytest
|
||||
|
||||
from metagpt.actions import ActionOutput
|
||||
from metagpt.actions.design_api import WriteDesign
|
||||
from metagpt.logs import logger
|
||||
from tests.metagpt.actions.mock import PRD_SAMPLE
|
||||
|
|
@ -18,9 +19,10 @@ async def test_design_api():
|
|||
|
||||
design_api = WriteDesign("design_api")
|
||||
|
||||
result = await design_api.run(prd)
|
||||
result = await design_api.run([ActionOutput(content=prd, instruct_content=None)])
|
||||
logger.info(result)
|
||||
assert len(result) > 0
|
||||
|
||||
assert result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -28,7 +30,7 @@ async def test_design_api_calculator():
|
|||
prd = PRD_SAMPLE
|
||||
|
||||
design_api = WriteDesign("design_api")
|
||||
result = await design_api.run(prd)
|
||||
result = await design_api.run([ActionOutput(content=prd, instruct_content=None)])
|
||||
logger.info(result)
|
||||
|
||||
assert len(result) > 10
|
||||
assert result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue