Daethyra / Build-RAGAI

Interactive notes (Jupyter Notebooks) for building AI-powered applications
Other
26 stars 3 forks source link

Read *all* JSON files via Glob #57

Closed Daethyra closed 9 months ago

Daethyra commented 9 months ago

Updates to how output files are named cause errors to throw during the execution of conv_html_to_markdown.py.

Solution:

  1. Import glob: At the top of conv_html_to_markdown.py, add import glob to use the glob module for file pattern matching.

  2. Update load_json Function:

import glob

def load_json_files(pattern):
    """
    Load data from multiple JSON files matching a pattern.

    Args:
        pattern (str): Glob pattern to match files.

    Returns:
        list: Aggregated data from all matched files.
    """
    aggregated_data = []
    for file_path in glob.glob(pattern):
        with open(file_path, "r", encoding="utf-8") as file:
            aggregated_data.extend(json.load(file))
    return aggregated_data
def main():
    # ... existing code ...
    try:
        # Load data from all output JSON files
        original_data = load_json_files("output-*.json")
        # ... rest of the existing code ...
Daethyra commented 9 months ago

wrong repo. FK!