def import_service(
    svc_import_path: str,
    *,
    working_dir: t.Optional[str] = None,
    reload: bool = False,
    model_store: ModelStore = Provide[BentoMLContainer.model_store],
) -> AnyService:
    """Import a Service instance from source code, by providing the svc_import_path
    which represents the module where the Service instance is created and optionally
    what attribute can be used to access this Service instance in that module

    Example usage:
        # When multiple service defined in the same module
        import_service("fraud_detector:svc_a")
        import_service("fraud_detector:svc_b")

        # Find svc by Python module name or file path
        import_service("fraud_detector:svc")
        import_service("fraud_detector.py:svc")
        import_service("foo.bar.fraud_detector:svc")
        import_service("./def/abc/fraud_detector.py:svc")

        # When there's only one Service instance in the target module, the attributes
        # part in the svc_import_path can be omitted
        import_service("fraud_detector.py")
        import_service("fraud_detector")
    """

    sys_path_modified = False
    prev_cwd = None
    global_model_store = BentoMLContainer.model_store.get()

    if working_dir is not None:
        prev_cwd = os.getcwd()
        working_dir = os.path.realpath(os.path.expanduser(working_dir))
        # Set cwd(current working directory) to the Bento's project directory,
        # which allows user code to read files using relative path
        os.chdir(working_dir)
    else:
        working_dir = os.getcwd()

    if working_dir not in sys.path:
        sys.path.insert(0, working_dir)
        sys_path_modified = True

    if model_store is not global_model_store:
        BentoMLContainer.model_store.set(model_store)
    elif (
        Path(working_dir).with_name(BENTO_YAML_FILENAME).exists()
        and (bento_models := Path(working_dir).with_name("models")).exists()
    ):
        if Path(model_store._fs.getsyspath("/")).absolute() != bento_models.absolute():
            BentoMLContainer.model_store.set(ModelStore(bento_models))
    try:
        return _do_import(svc_import_path, working_dir, reload)
    except ImportServiceError:
        BentoMLContainer.model_store.set(global_model_store)
        raise
    finally:
        if sys_path_modified and working_dir:
            # Undo changes to sys.path
            sys.path.remove(working_dir)
        if prev_cwd is not None:
            os.chdir(prev_cwd)
Import a Service instance from source code, by providing the svc_import_path
which represents the module where the Service instance is created and optionally
what attribute can be used to access this Service instance in that module

Example usage:
# When multiple service defined in the same module
import_service("fraud_detector:svc_a")
import_service("fraud_detector:svc_b")

# Find svc by Python module name or file path
import_service("fraud_detector:svc")
import_service("fraud_detector.py:svc")
import_service("foo.bar.fraud_detector:svc")
import_service("./def/abc/fraud_detector.py:svc")

# When there's only one Service instance in the target module, the attributes
# part in the svc_import_path can be omitted
import_service("fraud_detector.py")
import_service("fraud_detector")
src/bentoml/_internal/service/loader.py