From 38da8503bb06f9c0d4ccf1654b0c572d04ac65fa Mon Sep 17 00:00:00 2001 From: Michael Engel Date: Mon, 24 Feb 2025 09:13:33 +0100 Subject: [PATCH] Created abstract base class for models Signed-off-by: Michael Engel --- ramalama/model.py | 55 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/ramalama/model.py b/ramalama/model.py index a8ce7408..15b30c2d 100644 --- a/ramalama/model.py +++ b/ramalama/model.py @@ -36,7 +36,46 @@ $(error)s""" -class Model: +class ModelBase: + + def __not_implemented_error(self, param): + return NotImplementedError(f"ramalama {param} for '{type(self).__name__}' not implemented") + + def login(self, args): + raise self.__not_implemented_error("login") + + def logout(self, args): + raise self.__not_implemented_error("logout") + + def pull(self, args): + raise self.__not_implemented_error("pull") + + def push(self, source, args): + raise self.__not_implemented_error("push") + + def remove(self, args): + raise self.__not_implemented_error("rm") + + def bench(self, args): + raise self.__not_implemented_error("bench") + + def run(self, args): + raise self.__not_implemented_error("run") + + def perplexity(self, args): + raise self.__not_implemented_error("perplexity") + + def serve(self, args): + raise self.__not_implemented_error("serve") + + def exists(self, args): + raise self.__not_implemented_error("exists") + + def inspect(self, args): + raise self.__not_implemented_error("inspect") + + +class Model(ModelBase): """Model super class""" model = "" @@ -48,18 +87,6 @@ def __init__(self, model): self.directory = split[0] if len(split) > 1 else "" self.filename = split[1] if len(split) > 1 else split[0] - def login(self, args): - raise NotImplementedError(f"ramalama login for {self.type} not implemented") - - def logout(self, args): - raise NotImplementedError(f"ramalama logout for {self.type} not implemented") - - def pull(self, args): - raise NotImplementedError(f"ramalama pull for {self.type} not implemented") - - def push(self, source, args): - raise NotImplementedError(f"ramalama push for {self.type} not implemented") - def is_symlink_to(self, file_path, target_path): if os.path.islink(file_path): symlink_target = os.readlink(file_path) @@ -109,8 +136,6 @@ def attempt_to_use_versioned(self, conman, image, vers, args): except Exception: return False - return False - def _image(self, args): if args.image != DEFAULT_IMAGE: return args.image