<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_versions(config) -> dict: """Get versions of bel modules and tools"""


    # Collect bel package version
    try:
        import bel.__version__

        config["bel"]["version"] = bel.__version__.__version__
    except KeyError:
        config["bel"] = {"version": bel.__version__.__version__}
    except ModuleNotFoundError:
        pass

    # Collect bel_resources version
    try:
        import tools.__version__

        config["bel_resources"]["version"] = tools.__version__.__version__
    except KeyError:
        config["bel_resources"] = {"version": tools.__version__.__version__}
    except ModuleNotFoundError:
        pass

    # Collect bel_api version
    try:
        import __version__

        if __version__.__name__ == "BELBIO API":
            config["bel_api"]["version"] = __version__.__version__
    except KeyError:
        if __version__.__name__ == "BELBIO API":
            config["bel_api"] = {"version": __version__.__version__}
    except ModuleNotFoundError:
        pass