How adirthaborgohain/reportai works
Project type and purpose
• This is a Python-based CLI/open-source tool (not a web or full-stack app).
• Purpose: ingest structured AI chat messages → generate a formatted PDF research report (9–15 pages) using OpenAI/Anthropic LLMs.
File structure
• Top-level:
• report_ai/ (main package)
• requirements.txt, README.md, LICENSE
• report_ai/ subdirectories & files:
• assets/ – HTML templates, logos, screenshots (static resources for report cover, sections, disclaimers)
• common/utils/ – configuration loader (configs.yaml), environment variables (.env), logger, helper functions
• components/ – core “pipeline” steps: llms.py (API wrappers), deduplicate.py, convert.py (HTML→PDF), functions.py (report-building helpers)
• skeleton.py, section.py, summary.py, report.py – modules that assemble the high-level report structure, section content, executive summary, and orchestrate PDF rendering
• main.py – CLI entry point demonstrating usage
• reports/ – output directory containing sample.pdf
Key insights from the README
• Uses LLMs via OpenAI/Anthropic; configurable via environment variables/.env
• Pipeline: parse conversation → dedupe → format sections/tables/figures → produce PDF
• Depends on LangChain and other Python libraries
Main components and their relationships
a. CLI Entry Point (main.py)
• Reads user’s structured conversation input
• Loads config & API keys via common/utils
• Kicks off the ReportBuilder (report.py)
b. Report Pipeline
• skeleton.py: defines overall report structure (title page, table of contents, sections)
• section.py: generates each section by invoking llms.py (API calls) and functions.py (text/table formatting)
• summary.py: creates executive summary via a separate LLM call
• deduplicate.py: removes repeated sentences/phrases across sections
• convert.py: merges filled‐in HTML templates (assets/) into final PDF
c. Static Assets
• HTML templates, logos, disclaimers (report_ai/assets) used by convert.py to render pages
d. Utilities
• config loader reads .env & configs.yaml
• logger for structured logging
e. External Dependencies
• OpenAI/Anthropic LLM APIs
• PDF rendering library (e.g., WeasyPrint, PyPDF2—check requirements.txt)
• LangChain for prompt management
Architectural patterns & design principles
• Modular pipeline: each stage in its own component/module
• Single-responsibility: separation of concerns (LLM API calls vs. formatting vs. dedupe vs. conversion)
• Pluggable: LLM choice abstracted in llms.py, environment-driven config
• Template-driven output: HTML assets + conversion → PDF
Detailed but uncluttered
• If space allows, annotate each module with its primary responsibility (e.g., “deduplicate.py: remove repeated content”)
• Related modules (e.g., section.py and summary.py) under a “Content Generation” container
Essential elements
• The separation of stages (generation, dedupe, conversion)
• The abstraction of LLM providers behind llms.py
• The use of static HTML assets to drive PDF layout