def generate_readme()

in readme_generator.py [0:0]


def generate_readme(template_path: str, function_index: dict, examples_path: str) -> str:
  # Read the template file
  with open(template_path, 'r') as template_file:
    output_lines = template_file.readlines()

  output_lines.append("\n## Aggregate Functions\n")

  # Sort functions by function type (AGGREGATE first, then SCALAR) and then by number of arguments
  sorted_functions = sorted(function_index, key=lambda x: (x['type'], len(x['params'].split(','))), reverse=False)
  is_aggregate = True
  for function in sorted_functions:
    if is_aggregate and function['type'] == 'SCALAR':
      output_lines.append("\n## Scalar Functions\n")
      is_aggregate = False
    function_link = f"[{function['name']}{function['params']}](../{function['path']})"
    output_lines.append(f"\n### {function_link}\n{function['description']}\n")

  # Add examples section
  example_files = [f for f in os.listdir(examples_path) if f.endswith(".sql")]
  if example_files:
    output_lines.append("\n## Examples\n")
    for example_file in example_files:
      full_name = os.path.join(examples_path, example_file)
      output_lines.append(f"\n### [test/{example_file}](../{full_name})\n")
      with open(full_name, 'r') as f:
        sql_code = f.read()

      # Remove license header from examples
      sql_code_lines = sql_code.splitlines()
      start_index = 0
      for i, line in enumerate(sql_code_lines):
        if not line.startswith("/*") and not line.startswith(" *") and not line.startswith(" */"):
          start_index = i
          break
      sql_code_without_license = "\n".join(sql_code_lines[start_index:])

      # add project and dataset available in BQ
      sql_code_without_license = sql_code_without_license.replace('`$BQ_DATASET`', 'bqutil.datasketches')

      # Add the SQL code in a code block
      output_lines.append(f"```sql\n{sql_code_without_license}\n```\n")

  output_content = "".join(output_lines)
  return output_content