Skip to content

Commit

Permalink
Remove tokentrim dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Nov 21, 2023
1 parent ead2bce commit 6872e3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
22 changes: 17 additions & 5 deletions r2ai/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import json
import platform
import getpass
import tokentrim as tt
from rich.rule import Rule
import signal
import sys
Expand Down Expand Up @@ -533,10 +532,23 @@ def respond(self):
system_message = self.system_message + "\n\n" + info
system_message += self.environment()

messages = tt.trim(self.messages,
max_tokens=(self.context_window-self.max_tokens-25),
system_message=system_message)

if self.env["chat.trim"]:
## this stupid function is slow as hell and doesn not provides much goodies
## just ignore it by default
import tokentrim
messages = tokentrim.trim(self.messages,
max_tokens=(self.context_window-self.max_tokens-25),
system_message=system_message)
else:
messages = self.messages

msglen = 0
for msg in messages:
if "content" in msg:
msglen += len(msg["content"])
if msglen > 1024:
print("Query is too large.. you should consider triming old messages")
print(f"QueryLen {msglen}")
if self.env["debug"] == "true":
print(messages)

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
rich
inquirer
llama-cpp-python
tokentrim
huggingface_hub
appdirs
unidecode

0 comments on commit 6872e3a

Please sign in to comment.