From bf67b323c210f88ad04a053a911b549b4dd2478b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bj=C3=A4reholt?= Date: Wed, 14 Aug 2024 00:02:34 +0200 Subject: [PATCH] fix: enabled stricter linting and fixed lints (apparently needed given a25aa7d369dec79341500bcf735e4237def53052) --- gptme/commands.py | 4 ++-- gptme/logmanager.py | 11 ++++++----- gptme/server/api.py | 6 +++--- gptme/tools/_browser_playwright.py | 3 +-- gptme/util.py | 2 +- pyproject.toml | 4 ++++ 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/gptme/commands.py b/gptme/commands.py index 4d448184..0c3075de 100644 --- a/gptme/commands.py +++ b/gptme/commands.py @@ -143,8 +143,8 @@ def handle_cmd( print("Replaying conversation...") for msg in log.log: if msg.role == "assistant": - for msg in execute_msg(msg, ask=True): - print_msg(msg, oneline=False) + for reply_msg in execute_msg(msg, ask=True): + print_msg(reply_msg, oneline=False) case "impersonate": content = full_args if full_args else input("[impersonate] Assistant: ") msg = Message("assistant", content) diff --git a/gptme/logmanager.py b/gptme/logmanager.py index adb1717f..8e480013 100644 --- a/gptme/logmanager.py +++ b/gptme/logmanager.py @@ -13,7 +13,7 @@ from .constants import CMDFIX from .dirs import get_logs_dir -from .message import Message, print_msg, len_tokens +from .message import Message, len_tokens, print_msg from .prompts import get_prompt from .tools.reduce import limit_log, reduce_log @@ -184,11 +184,13 @@ def prepare_messages(self) -> list[Message]: def load( cls, logfile: PathLike, - initial_msgs: list[Message] = [get_prompt()], + initial_msgs: list[Message] | None = None, branch: str = "main", **kwargs, ) -> "LogManager": """Loads a conversation log.""" + if not initial_msgs: + initial_msgs = [get_prompt()] logsdir = get_logs_dir() if str(logsdir) not in str(logfile): # if the path was not fully specified, assume its a dir in logsdir @@ -251,9 +253,8 @@ def diff(self, branch: str) -> str | None: # walk the log forwards until we find a message that is different diff_i: int | None = None - for diff_i, (msg1, msg2) in enumerate( - zip_longest(self.log, self._branches[branch]) - ): + for i, (msg1, msg2) in enumerate(zip_longest(self.log, self._branches[branch])): + diff_i = i if msg1 != msg2: break else: diff --git a/gptme/server/api.py b/gptme/server/api.py index fedb5913..2d97e2cb 100644 --- a/gptme/server/api.py +++ b/gptme/server/api.py @@ -119,9 +119,9 @@ def api_conversation_generate(logfile: str): resp_msgs = [] log.append(msg) resp_msgs.append(msg) - for msg in execute_msg(msg, ask=False): - log.append(msg) - resp_msgs.append(msg) + for reply_msg in execute_msg(msg, ask=False): + log.append(reply_msg) + resp_msgs.append(reply_msg) return flask.jsonify( [{"role": msg.role, "content": msg.content} for msg in resp_msgs] diff --git a/gptme/tools/_browser_playwright.py b/gptme/tools/_browser_playwright.py index 5416e4e0..cc85c9cd 100644 --- a/gptme/tools/_browser_playwright.py +++ b/gptme/tools/_browser_playwright.py @@ -110,8 +110,7 @@ def _list_clickable_elements(page, selector=None) -> list[Element]: # List all clickable buttons clickable = page.query_selector_all(selector) - for i, el in enumerate(clickable): - # "selector": f"{tag_name}:has-text('{text}')", + for el in clickable: elements.append(Element.from_element(el)) return elements diff --git a/gptme/util.py b/gptme/util.py index 168393eb..734d03bb 100644 --- a/gptme/util.py +++ b/gptme/util.py @@ -146,7 +146,7 @@ def transform_examples_to_chat_directives(s: str, strict=False) -> str: r"(^|\n)([>] )?(.+):", r"\1\3:", s, - re.DOTALL, + flags=re.DOTALL, ) if strict: assert s != orig, "Couldn't find a message" diff --git a/pyproject.toml b/pyproject.toml index fa7714be..ff8bf5b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,6 +90,10 @@ all = [ [tool.ruff] +# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. +# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or +# McCabe complexity (`C901`) by default. +select = ["E4", "E7", "E9", "F", "B"] ignore = ["E402", "E501"] [tool.pytest.ini_options]