Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
operations: nlp: tools: dffml docs: write paper: Markdown saved to file
Browse files Browse the repository at this point in the history
Signed-off-by: John Andersen <[email protected]>
  • Loading branch information
pdxjohnny committed Apr 10, 2024
1 parent be1d289 commit faf18e3
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion operations/nlp/dffml_operations_nlp/tools/dffml_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,41 @@ class WritePaper(BaseModel):
)


# Sample JSON data, structured according to given Pydantic classes
def generate_markdown(write_paper_model: WritePaper):
markdown_content = f"# {write_paper_model.outline.title}\n\n"
for slug, section in write_paper_model.sections.items():
markdown_content += (
f"## {section.section_number} {section.title}\n{section.brief}\n\n"
)
for sub_slug, subsection in section.subsections.items():
markdown_content += f"### {subsection.section_number} {subsection.title}\n{subsection.comments}\n\n{subsection.text}\n\n"
return markdown_content


# Using the Pydantic model to parse and validate the data
data_path = pathlib.Path("open-architecture.json")
md_path = pathlib.Path("open-architecture.md")
if data_path.exists():
data_text = data_path.read_text()
write_paper_instance = WritePaper.model_validate_json(data_text)

# Generate Markdown content
markdown_content = generate_markdown(write_paper_instance)

md_path.write_text(markdown_content)

# Print or save the markdown content
import rich.console
import rich.markdown

rich_console = rich.console.Console(width=80)

rich_console.print(rich.markdown.Markdown(markdown_content))

sys.exit(0)


# with open("WritePaper.schema.json", "wt") as fileobj:
# print(json.dumps(WritePaperSection.model_json_schema(), indent=4,
# sort_keys=True), file=fileobj)
Expand Down Expand Up @@ -837,7 +872,7 @@ def do_llm_call(prompt):
write_paper.sections[write_paper_section.slug] = write_paper_section


pathlib.Path("open-architecture.json").write_text(write_paper.model_dump_json())
data_path.write_text(write_paper.model_dump_json())

print()

Expand Down

0 comments on commit faf18e3

Please sign in to comment.