def update_readme()

in scripts/internal/update_example_tables.py [0:0]


def update_readme(examples):
    with open("README.md", "r") as f:
        content = f.read()

    ordered_services = ["Vertex AI", "GKE", "Cloud Run"]

    for example_type in ["training", "inference", "evaluation"]:
        table_rows = []
        for service in ordered_services:
            if examples[service].get(example_type):
                for path, title in sorted(
                    examples[service][example_type], key=lambda x: x[1]
                ):
                    # Format the path to include 'examples/<service>'
                    table_rows.append(
                        (
                            service,
                            f"[{path}](./{path})",
                            title,
                        )
                    )

        if table_rows:
            table = format_table(["Service", "Example", "Title"], table_rows)
            pattern = (
                rf"(### {example_type.capitalize()} Examples\n\n)[\s\S]*?(\n\n###|\Z)"
            )
            replacement = rf"\1{table}\2"
            content = re.sub(pattern, replacement, content, flags=re.DOTALL)

    with open("README.md", "w") as f:
        f.write(content.rstrip() + "\n")