json to markdown

This commit is contained in:
femto 2023-09-11 12:48:44 +08:00
parent 6b0daa0312
commit d18a419d4b
5 changed files with 113 additions and 11 deletions

View file

@ -7,9 +7,9 @@
"""
import pytest
from metagpt.actions import ActionOutput
from metagpt.actions.design_api import WriteDesign
from metagpt.logs import logger
from metagpt.schema import Message
from tests.metagpt.actions.mock import PRD_SAMPLE
@ -19,7 +19,7 @@ async def test_design_api():
design_api = WriteDesign("design_api")
result = await design_api.run([ActionOutput(content=prd, instruct_content=None)])
result = await design_api.run([Message(content=prd, instruct_content=None)])
logger.info(result)
assert result
@ -30,7 +30,7 @@ async def test_design_api_calculator():
prd = PRD_SAMPLE
design_api = WriteDesign("design_api")
result = await design_api.run([ActionOutput(content=prd, instruct_content=None)])
result = await design_api.run([Message(content=prd, instruct_content=None)])
logger.info(result)
assert result

View file

@ -0,0 +1,60 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time : 2023/9/11 11:53
@Author : femto Zheng
@File : test_json_to_markdown.py
"""
from metagpt.utils.json_to_markdown import json_to_markdown
def test_json_to_markdown():
# Example nested JSON data
json_data = {
"title": "Sample JSON to Markdown Conversion",
"description": "Convert JSON to Markdown with headings and lists.",
"tags": ["json", "markdown", "conversion"],
"content": {
"section1": {"subsection1": "This is a subsection.", "subsection2": "Another subsection."},
"section2": "This is the second section content.",
},
}
# Convert JSON to Markdown with nested sections
markdown_output = json_to_markdown(json_data)
expected = """## title
Sample JSON to Markdown Conversion
## description
Convert JSON to Markdown with headings and lists.
## tags
- json
- markdown
- conversion
## content
### section1
#### subsection1
This is a subsection.
#### subsection2
Another subsection.
### section2
This is the second section content.
"""
# Print or use the generated Markdown
# print(markdown_output)
assert expected == markdown_output