Skip to content

Commit

Permalink
Merge pull request #215 from tisnik/dont-overwrite-loop-variable
Browse files Browse the repository at this point in the history
Don't overwrite loop variable
  • Loading branch information
tisnik authored Dec 16, 2024
2 parents 0e10d24 + 5ad609d commit e963185
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions ols/utils/token_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ def limit_conversation_history(
) -> tuple[list[str], bool]:
"""Limit conversation history to specified number of tokens."""
total_length = 0
formatted_history: list[str] = []

for index, message in enumerate(reversed(history)):
for original_message in reversed(history):
# Restructure messages as per model
message = restructure_history(message, model)
message = restructure_history(original_message, model)

message_length = TokenHandler._get_token_count(self.text_to_tokens(message))
total_length += message_length
Expand All @@ -194,6 +195,7 @@ def limit_conversation_history(
logger.debug(
"History truncated, it exceeds available %d tokens.", limit
)
return history[len(history) - index :], True
return formatted_history[::-1], True
formatted_history.append(message)

return history, False
return formatted_history[::-1], False
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.ruff]

# description of all rules are available on https://docs.astral.sh/ruff/rules/
lint.select = ["D", "E", "F", "W", "C", "S", "I", "TCH", "SLOT", "RUF", "C90", "N", "YTT", "ASYNC", "A", "C4", "T10", "PGH", "FURB", "PERF", "AIR", "NPY", "FLY"]
lint.select = ["D", "E", "F", "W", "C", "S", "I", "TCH", "SLOT", "RUF", "C90", "N", "YTT", "ASYNC", "A", "C4", "T10", "PGH", "FURB", "PERF", "AIR", "NPY", "FLY", "PLW2901"]

# we need to check 'mood' of all docstrings, this needs to be enabled explicitly
lint.extend-select = ["D401"]
Expand Down

0 comments on commit e963185

Please sign in to comment.