From 7fc648183a18d82ce02737790c5df760bd216f5e Mon Sep 17 00:00:00 2001 From: lu-ny Date: Tue, 10 Dec 2024 19:02:55 -0500 Subject: [PATCH] removed formatting tools from make format to avoid formatting redundancy, we should have one source-of-truth for formatting, which is the pre-commit --- .pre-commit-config.yaml | 11 ++++------- Makefile | 1 - .../adalflow/components/retriever/bm25_retriever.py | 4 +++- adalflow/adalflow/core/component.py | 4 +++- adalflow/adalflow/optim/_llm_optimizer.py | 6 +++--- .../adalflow/optim/few_shot/bootstrap_optimizer.py | 3 ++- adalflow/adalflow/optim/parameter.py | 6 +++--- adalflow/adalflow/optim/trainer/trainer.py | 3 ++- adalflow/adalflow/tracing/generator_state_logger.py | 6 +++--- pyproject.toml | 6 ------ 10 files changed, 23 insertions(+), 27 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fa2222b1..bf4be365 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,19 +23,16 @@ repos: - id: ruff args: ['--fix', '--config=pyproject.toml'] exclude: ^docs/|.*\.(json|yaml|md|txt)$ - - id: ruff-format - args: ['--config=pyproject.toml'] - exclude: ^docs/|.*\.(json|yaml|md|txt)$ # stage files after ruff - repo: local hooks: - - id: git-add - name: git-add - entry: git add + - id: run-make-format + name: Run Make Format + entry: make format language: system stages: [commit] - pass_filenames: true + pass_filenames: false # - repo: https://github.com/pycqa/flake8 # rev: 4.0.1 diff --git a/Makefile b/Makefile index 01f5c64a..c95043b8 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,6 @@ setup: format: $(PYTHON) black $(SRC_DIR) --config pyproject.toml $(PYTHON) ruff check --fix $(SRC_DIR) - $(PYTHON) ruff format $(SRC_DIR) # remove git ls-files | xargs pre-commit run black --files, causes a circular dependency # Run lint checks using Ruff diff --git a/adalflow/adalflow/components/retriever/bm25_retriever.py b/adalflow/adalflow/components/retriever/bm25_retriever.py index 5e4badb1..ab7f3fea 100644 --- a/adalflow/adalflow/components/retriever/bm25_retriever.py +++ b/adalflow/adalflow/components/retriever/bm25_retriever.py @@ -232,7 +232,9 @@ def _initialize(self, corpus: List[List[str]]): def _calc_idf(self): idf_sum = 0 - negative_idf = [] # idf can be negative if word is too common: more than half of the documents + negative_idf = ( + [] + ) # idf can be negative if word is too common: more than half of the documents self.idf: Dict[str, float] = {} for token, freq in self.nd.items(): idf = math.log(self.total_documents - freq + 0.5) - math.log(freq + 0.5) diff --git a/adalflow/adalflow/core/component.py b/adalflow/adalflow/core/component.py index 49c75c6c..3d3f689d 100644 --- a/adalflow/adalflow/core/component.py +++ b/adalflow/adalflow/core/component.py @@ -138,7 +138,9 @@ def call(self, query: str) -> str: training: bool teacher_mode: bool = False tracing: bool = False - name: str = "Component" # name will help with GradComponent output naming as "{name}_output" + name: str = ( + "Component" # name will help with GradComponent output naming as "{name}_output" + ) _component_type = "base" # def _generate_unique_name(self): diff --git a/adalflow/adalflow/optim/_llm_optimizer.py b/adalflow/adalflow/optim/_llm_optimizer.py index 0ba093b1..3f321e92 100644 --- a/adalflow/adalflow/optim/_llm_optimizer.py +++ b/adalflow/adalflow/optim/_llm_optimizer.py @@ -114,9 +114,9 @@ def __init__( # Ensure the temperature is at least 1 model_kwargs["temperature"] = max(1, model_kwargs.get("temperature", 1)) - self.instruction_history: List[ - Instruction - ] = [] # trace the history of the instructions + self.instruction_history: List[Instruction] = ( + [] + ) # trace the history of the instructions self.starter_instruction: Optional[str] = None if self.instruction_parameter.data is not None: self.starter_instruction = self.instruction_parameter.data diff --git a/adalflow/adalflow/optim/few_shot/bootstrap_optimizer.py b/adalflow/adalflow/optim/few_shot/bootstrap_optimizer.py index a088f535..eeec61c8 100644 --- a/adalflow/adalflow/optim/few_shot/bootstrap_optimizer.py +++ b/adalflow/adalflow/optim/few_shot/bootstrap_optimizer.py @@ -139,7 +139,8 @@ def sample( ) # if demo.id in demos and demos[demo.id].score is not None: w = ( - w - student_demo_score + w + - student_demo_score # w - demos[demo.id].score ) # assign higher weights to failed demos but successful in augmented if w < 0: diff --git a/adalflow/adalflow/optim/parameter.py b/adalflow/adalflow/optim/parameter.py index a12fe00a..e5241939 100644 --- a/adalflow/adalflow/optim/parameter.py +++ b/adalflow/adalflow/optim/parameter.py @@ -170,9 +170,9 @@ def __init__( self._score: float = score # end to end evaluation score self._student_traces: Dict[str, DataClass] = {} # id - self._demos: List[ - DataClass - ] = [] # used for the optimizer to save the proposed demos + self._demos: List[DataClass] = ( + [] + ) # used for the optimizer to save the proposed demos self._previous_demos: List[DataClass] = [] self.eval_input = eval_input diff --git a/adalflow/adalflow/optim/trainer/trainer.py b/adalflow/adalflow/optim/trainer/trainer.py index 343a973d..03127131 100644 --- a/adalflow/adalflow/optim/trainer/trainer.py +++ b/adalflow/adalflow/optim/trainer/trainer.py @@ -1517,7 +1517,8 @@ def _downsample_move_batch( error_indices = [i for i, score in enumerate(acc_score_list) if score <= 0.5] if ( - len(error_indices) + len(correct_indices) <= max_moving_batch_size + len(error_indices) + len(correct_indices) + <= max_moving_batch_size # and len(correct_indices) <= max_moving_batch_size ): return all_samples, all_losses, all_y_preds, acc_score_list diff --git a/adalflow/adalflow/tracing/generator_state_logger.py b/adalflow/adalflow/tracing/generator_state_logger.py index 4e64086a..6a86cd0c 100644 --- a/adalflow/adalflow/tracing/generator_state_logger.py +++ b/adalflow/adalflow/tracing/generator_state_logger.py @@ -59,9 +59,9 @@ def __init__( self.filename = filename or "generator_state_trace.json" self.filepath = os.path.join(self.filepath, self.filename) - self._trace_map: Dict[ - str, List[GeneratorStatesRecord] - ] = {} # generator_name: [prompt_states] + self._trace_map: Dict[str, List[GeneratorStatesRecord]] = ( + {} + ) # generator_name: [prompt_states] # load previous records if the file exists if os.path.exists(self.filepath): self.load(self.filepath) diff --git a/pyproject.toml b/pyproject.toml index 1ecc0b9c..02f0cba2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,9 +79,3 @@ lint.extend-ignore = [ "UP007", # Wants | over Union, which breaks 3.8 ] exclude = ["docs/*"] - -[tool.ruff.format] -quote-style = "double" -indent-style = "space" -skip-magic-trailing-comma = false -line-ending = 'auto'