def add_relative_imports(
    file_path: str,
    relative_imports_to_add: set[str],
) -> None:
    """Add relative imports to a file.

    Args:
        file_path (str): The file to add to.
        relative_imports_to_add (set[str]): The set of relative imports to add
    """
    # Get the directory name where all the files are located
    dir_name = os.path.dirname(file_path)

    with open(file_path, 'r', encoding='utf-8') as f:
        source = f.read()

    tree = ast.parse(source)

    for relative_import in relative_imports_to_add:
        import_path = os.path.join(dir_name, relative_import + '.py')
        # Open up the file we are adding an import to find something to import from it
        with open(import_path, 'r', encoding='utf-8') as f:
            import_source = f.read()
        import_tree = ast.parse(import_source)
        item_to_import = None
        for node in ast.walk(import_tree):
            # Find the first function or class
            if isinstance(node,
                          ast.FunctionDef) or isinstance(node, ast.ClassDef):
                # Get its name to import it
                item_to_import = node.name
                break

        if item_to_import is None:
            item_to_import = '*'

        # This will look like `from .relative_import import item_to_import`
        import_node = ast.ImportFrom(
            module=relative_import,
            names=[ast.alias(name=item_to_import, asname=None)],
            level=1,
        )

        # Insert near the top of the file, but past the from __future__ import
        tree.body.insert(2, import_node)

    with open(file_path, 'w', encoding='utf-8') as f:
        f.write(ast.unparse(tree))
Add relative imports to a file.

    Args:
        file_path (str): The file to add to.
        relative_imports_to_add (set[str]): The set of relative imports to add
    
llmfoundry/utils/huggingface_hub_utils.py