Skip to content

Commit

Permalink
fix: enabled stricter linting and fixed lints (apparently needed given
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Aug 13, 2024
1 parent a25aa7d commit bf67b32
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions gptme/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions gptme/logmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions gptme/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions gptme/tools/_browser_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gptme/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit bf67b32

Please sign in to comment.