refactor into Model.token_count()

This commit is contained in:
Paul Gauthier 2023-11-14 10:11:13 -08:00
parent 90f57664a6
commit c24a4a4392
3 changed files with 24 additions and 10 deletions

View file

@ -1,4 +1,3 @@
import json
import re
import subprocess
import sys
@ -109,14 +108,13 @@ class Commands:
dict(role="system", content=self.coder.gpt_prompts.main_system),
dict(role="system", content=self.coder.gpt_prompts.system_reminder),
]
tokens = self.coder.main_model.token_count(json.dumps(msgs))
tokens = self.coder.main_model.token_count(msgs)
res.append((tokens, "system messages", ""))
# chat history
msgs = self.coder.done_messages + self.coder.cur_messages
if msgs:
msgs = [dict(role="dummy", content=msg) for msg in msgs]
msgs = json.dumps(msgs)
tokens = self.coder.main_model.token_count(msgs)
res.append((tokens, "chat history", "use /clear to clear"))