From 9ada36e30b835d6eb54989b48100df5682c13822 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 4 Jun 2024 14:36:19 +0800 Subject: [PATCH] fix: restore python linting. (#2228) * fix: restore python linting. Signed-off-by: ifuryst * update: extend the Python lint check to evaluation. Signed-off-by: ifuryst * Update evaluation/logic_reasoning/instruction.txt --------- Signed-off-by: ifuryst Co-authored-by: Boxuan Li --- .github/workflows/lint.yml | 9 +-------- Makefile | 2 +- agenthub/browsing_agent/prompt.py | 6 ++++-- agenthub/browsing_agent/utils.py | 2 +- evaluation/EDA/game.py | 5 ++++- evaluation/gaia/scorer.py | 8 ++++++-- evaluation/logic_reasoning/instruction.txt | 5 ++--- 7 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0ff1f383e0..4fff2a1754 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -47,11 +47,4 @@ jobs: - name: Install pre-commit run: pip install pre-commit==3.7.0 - name: Run pre-commit hooks - if: github.ref != 'refs/heads/main' - run: | - git fetch https://github.com/OpenDevin/OpenDevin.git main:main && \ - pre-commit run \ - --files \ - $(git diff --name-only $(git merge-base main $(git branch --show-current)) $(git branch --show-current) | tr '\n' ' ') \ - --show-diff-on-failure \ - --config ./dev_config/python/.pre-commit-config.yaml + run: pre-commit run --files opendevin/**/* agenthub/**/* evaluation/**/* --show-diff-on-failure --config ./dev_config/python/.pre-commit-config.yaml diff --git a/Makefile b/Makefile index 098888d80d..29db6389de 100644 --- a/Makefile +++ b/Makefile @@ -172,7 +172,7 @@ install-precommit-hooks: lint-backend: @echo "$(YELLOW)Running linters...$(RESET)" - @poetry run pre-commit run --files $$(git diff --name-only $$(git merge-base main $$(git branch --show-current)) $$(git branch --show-current) | tr '\n' ' ') --show-diff-on-failure --config $(PRECOMMIT_CONFIG_PATH) + @poetry run pre-commit run --files opendevin/**/* agenthub/**/* evaluation/**/* --show-diff-on-failure --config $(PRECOMMIT_CONFIG_PATH) lint-frontend: @echo "$(YELLOW)Running linters for frontend...$(RESET)" diff --git a/agenthub/browsing_agent/prompt.py b/agenthub/browsing_agent/prompt.py index 8f6702adfa..5c62b67204 100644 --- a/agenthub/browsing_agent/prompt.py +++ b/agenthub/browsing_agent/prompt.py @@ -494,11 +494,13 @@ def _get_action_space(flags: Flags) -> AbstractActionSet: action_space = PythonActionSet(strict=flags.is_strict) if flags.multi_actions: warn( - f'Flag action_space={repr(flags.action_space)} incompatible with multi_actions={repr(flags.multi_actions)}.' + f'Flag action_space={repr(flags.action_space)} incompatible with multi_actions={repr(flags.multi_actions)}.', + stacklevel=2, ) if flags.demo_mode != 'off': warn( - f'Flag action_space={repr(flags.action_space)} incompatible with demo_mode={repr(flags.demo_mode)}.' + f'Flag action_space={repr(flags.action_space)} incompatible with demo_mode={repr(flags.demo_mode)}.', + stacklevel=2, ) return action_space case 'bid': diff --git a/agenthub/browsing_agent/utils.py b/agenthub/browsing_agent/utils.py index 6466187397..e98ae3c5ce 100644 --- a/agenthub/browsing_agent/utils.py +++ b/agenthub/browsing_agent/utils.py @@ -16,7 +16,7 @@ def yaml_parser(message): valid = True retry_message = '' except yaml.YAMLError as e: - warn(str(e)) + warn(str(e), stacklevel=2) value = {} valid = False retry_message = "Your response is not a valid yaml. Please try again and be careful to the format. Don't add any apology or comment, just the answer." diff --git a/evaluation/EDA/game.py b/evaluation/EDA/game.py index 09ec16ca82..1c057ca8f8 100644 --- a/evaluation/EDA/game.py +++ b/evaluation/EDA/game.py @@ -9,6 +9,7 @@ from retry import retry LOGGER = logging.getLogger(__name__) + class Q20Game: def __init__( self, @@ -19,8 +20,10 @@ class Q20Game: temperature: float = 0.8, openai_api: bool = True, openai_api_key: Optional[str] = None, - guesser_kargs={}, + guesser_kargs=None, ) -> None: + if guesser_kargs is None: + guesser_kargs = {} self.item = item self.answerer_model = answerer_model self.guesser_model = guesser_model diff --git a/evaluation/gaia/scorer.py b/evaluation/gaia/scorer.py index da4177d61b..f361485cc9 100644 --- a/evaluation/gaia/scorer.py +++ b/evaluation/gaia/scorer.py @@ -17,8 +17,10 @@ def normalize_number_str(number_str: str) -> float: def split_string( s: str, - char_list: list[str] = [',', ';'], + char_list: list[str] = None, ) -> list[str]: + if char_list is None: + char_list = [',', ';'] pattern = f"[{''.join(char_list)}]" return re.split(pattern, s) @@ -51,7 +53,9 @@ def question_scorer( # check length is the same if len(gt_elems) != len(ma_elems): warnings.warn( - 'Answer lists have different lengths, returning False.', UserWarning + 'Answer lists have different lengths, returning False.', + UserWarning, + stacklevel=2, ) return False diff --git a/evaluation/logic_reasoning/instruction.txt b/evaluation/logic_reasoning/instruction.txt index 447634793e..bb49e883c7 100644 --- a/evaluation/logic_reasoning/instruction.txt +++ b/evaluation/logic_reasoning/instruction.txt @@ -1,6 +1,6 @@ -You are a helpful assistant assigned with logic reasoning task. You need to determine the correctness of a query given some facts and fules. +You are a helpful assistant assigned with logic reasoning task. You need to determine the correctness of a query given some facts and rules. you can interact with an interactive Python (Jupyter Notebook) environment and receive the corresponding output when needed. The code should be enclosed using "" tag. -In this task, you need to use the code in [[logic_inference_path.py]] to help you. Specifically, you first need to instantiate a **LogicInferenceEngine** class and use the **safe_execute_program** method to prove the **logic programs**. You should receive *answer*, *flag*, *error_message* from the output. +In this task, you need to use the code in [[logic_inference_path.py]] to help you. Specifically, you first need to instantiate a **LogicInferenceEngine** class and use the **safe_execute_program** method to prove the **logic programs**. You should receive *answer*, *flag*, *error_message* from the output. An example would be look like this: @@ -17,4 +17,3 @@ dataset_name: logic_programs: [[logic_programs]] -