From 1b180ad0124f52c7a916b94660ff0ec08fc02ab8 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Tue, 24 Dec 2024 12:49:52 +0000 Subject: [PATCH] refactor: change methods not using its bound instance to staticmethods The method doesn't use its bound instance. Decorate this method with `@staticmethod` decorator, so that Python does not have to instantiate a bound method for every instance of this class thereby saving memory and computation. Read more about staticmethods [here](https://docs.python.org/3/library/functions.html#staticmethod). --- src/everyai/classfier/classfy.py | 12 ++++++++---- src/everyai/generator/generate.py | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/everyai/classfier/classfy.py b/src/everyai/classfier/classfy.py index 8917be5..56b9697 100644 --- a/src/everyai/classfier/classfy.py +++ b/src/everyai/classfier/classfy.py @@ -190,16 +190,20 @@ def _split_data(self, path: Path): raise return self.model - def _tokenize(self): + @staticmethod + def _tokenize(): return None - def train(self): + @staticmethod + def train(): return None - def test(self): + @staticmethod + def test(): return None - def predict(self): + @staticmethod + def predict(): return None def show_score(self): diff --git a/src/everyai/generator/generate.py b/src/everyai/generator/generate.py index 86044a9..bb3faf8 100644 --- a/src/everyai/generator/generate.py +++ b/src/everyai/generator/generate.py @@ -20,8 +20,9 @@ def __init__(self, config: dict, format: Callable[[str], str] = None): self.model = None self.tokenizer = None + @staticmethod def _openai_generate( - self, input: str, base_url: str, model_name: str, api_key: str = "0" + input: str, base_url: str, model_name: str, api_key: str = "0" ) -> str: client = OpenAI(api_key=api_key, base_url=base_url) messages = [{"role": "user", "content": input}]